将区域限制为给定角色 [英] Restrict Area to a given role
本文介绍了将区域限制为给定角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 MVC2 中有一个区域设置,称为 Admin/
,我希望我只希望属于管理员"角色的用户具有访问权限.我知道我可以用 [Authorize(Roles="admins")]
装饰每个方法,但是当您谈论具有多个动作的多个控制器时,这似乎很乏味.
I have an area setup in MVC2, called Admin/
, which I want I only want Users who belong to the role "admins" to have access. I know I can decorate each of the methods with [Authorize(Roles="admins")]
, but this seems tedious when your talking about multiple controllers with multiple actions.
有没有更好更干净的方法?
Is there an better and cleaner way?
推荐答案
您可以定义一个用该属性修饰的基本控制器,该区域中的所有控制器都源自该属性.
You could define a base controller decorated with this attribute that all controllers in the area derive from.
这篇关于将区域限制为给定角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文