将区域限制为给定角色

发布于 2024-09-10 08:01:02 字数 177 浏览 1 评论 0原文

我在 MVC2 中设置了一个名为 Admin/ 的区域,我只希望属于“admins”角色的用户具有访问权限。我知道我可以用 [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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一念一轮回 2024-09-17 08:01:02

您可以定义一个用此属性装饰的基本控制器,该区域中的所有控制器都派生自该属性。

You could define a base controller decorated with this attribute that all controllers in the area derive from.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文