ASP.NET MVC: Can I say [Authorize Roles=“Administrators”] on the Controller class, but have one public action?

前端 未结 3 1681
天命终不由人
天命终不由人 2021-01-13 04:24

I started off using the default project\'s AccountController, but I\'ve extended/changed it beyond recognition. However, in common with the original I have a

3条回答
  •  再見小時候
    2021-01-13 05:07

    You can use AuthorizeAttribute on your class

    http://msdn.microsoft.com/en-us/library/system.web.mvc.authorizeattribute.aspx

    For relaxing you can implement for example a custom action filter attribute like this (I didn' test if it works).

    public class GetRidOfAutorizationAttribute : AuthorizeAttribute 
    {
    public override void OnAuthorization(AuthorizationContext filterContext)
    {
    
    // you can for example do nothing
    filterContext.Result = new EmptyResult(); 
    
    }
    }
    

提交回复
热议问题