Can user authorization be set on a per-controller basis in web.config? (cannot use AuthorizeAttribute)

情到浓时终转凉″ 提交于 2019-12-02 02:02:29
venerik

In our environment we use this approach:

The names of Active Directory groups are stored in the app-settings. These names are different per environment.

Next we created a subtype of AuthorizeAttribute called AuthorizeWritersAttribute like this:

public class AuthorizeWritersAttribute : AuthorizeAttribute 
{
    public AuthorizeWritersAttribute()
    {
        Roles = ConfigurationManager.AppSettings["SolutionName:AuthorizedWriters"];
        // Actually we removed the dependency on ConfigurationManager but for brevity this suffices.
    }
}

Finally we apply this attribute to our controllers:

[AuthorizeWriters]
public class BlogController : Controller
{
    ....
}

We use AD-groups but AD-accounts should work as well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!