使用全局过滤器将角色授权应用于整个mvc应用程序
我在 MVC 应用程序上使用全局授权过滤器,以确保用户在访问我的应用程序之前经过身份验证,但我想更进一步。我有三个 AD 组,用户可能可以成为其中的成员,并且我希望全局过滤器也检查这三个组之一。
我不想向应用程序中的每个控制器添加三个授权属性。我将如何编写全局过滤器以包含角色授权?
谢谢!
I'm using a global authorization filter on my MVC app to ensure that users are authenticated before they access my app, but I'd like to take it one step further. I have three AD groups that the users can potenially be a member of and I'd like the global filter to check for one of those three groups as well.
I do not want to add three authorize attributes to every controller in my application. How would I write the global filter to include role authorization?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以配置基于角色的成员资格提供程序,它本质上将使用您的自定义逻辑调用授权服务,并且您可以在需要检查的配置文件中提及角色。整个逻辑可以封装在一个属性内,并在路由上进行装饰。
You can configure a Role-Based membership provider , which essentially will call an Authorize service with your custom logic and you can mention the roles in a config file you need to check against. This entire logic can be encapsulated inside an attribute , decorated over the Routes.