如何在 ASP.NET MVC3 中使用基于 Windows 身份验证的自定义基于角色的授权?

发布于 12-29 20:11 字数 397 浏览 3 评论 0原文

我正在创建一个具有 Windows 身份验证 的 ASP.NET MVC3 Intranet 应用程序。我只希望域用户使用此应用程序。一旦域用户通过身份验证(使用 Active Directory),我计划创建用户(使用 AD 用户名)、角色和角色。 SQL Server 中的 UserRoles 表用于授权

因此,如果用户是具有某些权限集(访问控制器/操作)的角色的一部分,我应该只允许该角色中的用户执行/查看它们。

例如:如果有一个操作 /Locations/Create,则允许执行该操作的角色只能执行该操作。

有人可以给我一些指点吗?我是否应该创建自定义操作过滤器,并将过滤器属性用于我希望过滤器应用到的任何操作方法?

I'm creating an ASP.NET MVC3 intranet application with Windows authentication. I only want domain users to use this application. Once a domain user is authenticated (with Active Directory), I'm planning to create Users (with AD username), Roles & UserRoles tables in SQL Server for authorization.

So if an user is a part of a role which has some set of permissions (to access controllers/actions), I should only allow the users in that role to execute/view them.

Eg: if there is an action /Locations/Create, the roles which are allowed to perform that, can only do that.

Can somebody give me some pointers? Should I create a custom action filter, and use filter attribute to any action method that I want the filter to apply to?

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

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

发布评论

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

评论(1

满意归宿2025-01-05 20:11:36

要限制对 ASP.NET MVC 视图的访问,您可以限制对
呈现视图的操作方法。为了实现这一点,MVC
框架提供了AuthorizeAttribute类。

示例:

[Authorize(Roles = "Admin, Super User")]
public ActionResult AdministratorsOnly()
{
 return View();
}

请参阅此处了解更多详细信息。

请注意,使用 [Authorize] 属性需要您使用某种会员资格提供程序。

To restrict access to an ASP.NET MVC view, you restrict access to the
action method that renders the view. To accomplish this, the MVC
framework provides the AuthorizeAttribute class.

Example:

[Authorize(Roles = "Admin, Super User")]
public ActionResult AdministratorsOnly()
{
 return View();
}

See here for more details.

Note that using the [Authorize] attribute requires you to use some sort of Membership provider.

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