简体   繁体   中英

How to add custom authorization filter to method not controller in asp net core?

When I add custom IAuthorization attribute to controller method it works, but when I add it to method that is not part of controller method, IAuthorization method does not execute. Why?

public interface ICasbinBLL
{
    public abstract string objectId { get; set; }

    [ClaimRequirement("userId", "delete")]
    string DeleteMonitoring();
}

public class CasbinBLL : ICasbinBLL
{
    public string objectId { get; set; }

    [ClaimRequirement("userId", "delete")]
    public string DeleteMonitoring()
    {
        return objectId;
    }
}

IAuthorizationFilter is one of the filters in ASP.NET Core. Filters are executed by ASP.NET Core framework in filter pipeline .

Filters run within the ASP.NET Core action invocation pipeline, sometimes referred to as the filter pipeline. The filter pipeline runs after ASP.NET Core selects the action to execute.

If you add filters to your own types, ASP.NET Core does not know how to execute them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM