我正在创建具有 Windows身份验证的ASP.NET MVC3 Intranet应用程序。我只希望域用户使用此应用程序。一旦域用户经过身份验证(使用 Active Directory ),我计划在SQL Server中创建用户(带广告用户名),为授权 因此,如果用户是具有某些权限的角色的一部分(访问控制器/动作),我应该只允许该角色中的用户执行/查看它们。

例如:如果存在动作/位置/创建,则允许执行该角色,只能执行此操作。

有人可以给我一些指针吗?如果我创建自定义操作过滤器,并将过滤器属性使用过滤器属性到我希望过滤器适用的任何操作方法?

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top