How to add global `AuthorizeFilter` or `AuthorizeAttribute` in ASP.NET Core?

后端 未结 3 2005
情歌与酒
情歌与酒 2020-12-03 07:01

In ASP.NET MVC 4 and below we just add the following in Global.asax:

GlobalFilters.Filters.Add(new AuthorizeAttribute() { Roles = \"Admin, S         


        
3条回答
  •  被撕碎了的回忆
    2020-12-03 07:33

    You can also use the below code. This is using a type rather than an instance.

    services.AddMvc(options =>
    {
        options.Filters.Add(typeof(AuthorizeFilter));
    });
    

    And using Dependency Injection you can resolve the policy Object.

提交回复
热议问题