【发布时间】:2017-05-16 21:31:51
【问题描述】:
我在 Visual Studio 2015 中使用带有 Windows 身份验证的 ASP.NET MVC 5。目前,用户通过 Web.config 文件中的以下内容无缝连接到应用程序 - 没有登录屏幕:
<system.web>
<authentication mode="Windows" />
<authorization>
<deny users="?" />
</authorization>
</system.web>
那么Global.asax.cs有这个授权:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
GlobalFilters.Filters.Add(new System.Web.Mvc.AuthorizeAttribute()
{ Roles = "Some-AD-Group, Another-AD-Group" });
}
上述过滤器将允许进入应用程序的人员限制为 AD 组。我想使用 SQL Server 上的内置 [AspNet*] 表来管理授权并将用户与角色匹配。
这个example 让我可以创建一个自定义授权,但是我如何从[AspNetUserRoles] 表中获取用户的角色,以及在用户会话期间我将其存储在哪里?
这里是另一个example,它适用于角色,但不确定从哪里得到它们。 article 中也有很多很好的信息,但没有将其与 Windows 身份验证联系起来。
感谢您的帮助。
更新:过滤器将替换为 AspNetUserRoles;目前这只是一个绷带,可以让人们远离,直到我们弄清楚这件事情。
【问题讨论】:
标签: c# asp.net asp.net-mvc asp.net-mvc-4 asp.net-identity