简体   繁体   中英

Resource Specific Authorization in ASP.NET MVC 6

I want to use a resource ( User object in this case) in my authorization policy and I have something like this.

public class CountryAuthorizationHandler : 
          AuthorizationHandler<OperationAuthorizationRequirement, User> 
{   
    protected override void Handle(AuthorizationContext context,  
               OperationAuthorizationRequirement requirement, User user)
    {   
        if(context.User.HasClaim(ClaimTypes.Country, user.Country))
               context.Succeed(requirement);
    }   
}

I don't think I can use this declaratively through Authorize but how can I use it imperatively within my controller action method, for example, where I have my User object? Any code sample or link to it will be appreciated.

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