Authorize Attribute with Multiple Roles

前端 未结 5 1309
长发绾君心
长发绾君心 2020-12-02 07:00

I would like to add Authorization to a controller, for multiple Roles at once.

Normally that would look like this:

[Authorize(Roles = \"RoleA,RoleB,R         


        
5条回答
  •  半阙折子戏
    2020-12-02 07:13

    Make sure you are deriving your custom attribute class off System.Web.Mvc.AuthorizeAttribute and NOT System.Web.Http.AuthorizeAttribute.

    I ran into the same problem. Once I changed it, everything worked.

    You may also want to add the following to your custom attribute class:

    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true, AllowMultiple = true)] 
    

提交回复
热议问题