我试图认证使用ASP.NET MVC中的用户和组对Active Directory。
我把所有我的类(除了帐户类)以下属性:
[Authorize (Roles="SubcontractDB Users")]
此组位于活动目录中的OU = Area-> OU = Groups-> OU = Company-> CN = SubcontractDB下。我假设我还需要在web.config中设置一个RoleManager,我试图做如下:
<roleManager defaultProvider="ADRoleProvider"> <providers> <clear /> <add name="ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider" connectionStringName="ADConnectionString" attributeMapUsername="sAMAccountName" /> </providers> </roleManager>
我的连接字符串是:
<add name="ADConnectionString" connectionString="LDAP://blah.com:389/DC=blah,DC=wateva,DC=com"/>
解决方法
不再需要在ASP.NET MVC 3中为此功能实现您自己的属性。AspNetwindowsTokenRoleProvider与Active Directory用户和组配合使用。要与AuthorizeAttribute一起使用,您需要将以下内容添加到您的web.config中:
<authentication mode="Windows" /> <roleManager enabled="true" defaultProvider="AspNetwindowsTokenRoleProvider"> <providers> <clear /> <add name="AspNetwindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" /> </providers> </roleManager>
然后,在您的控制器或操作方法上,您可以参考Active Directory组,如:
[Authorize(Roles = "YOURDOMAIN\\Group1,YOURDOMAIN\\Group2")]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。