ASP.NET 成员资格 - 使用哪个 RoleProvider 以便 User.IsInRole() 检查 ActiveDirectory 组?
实际上非常简单的问题:
我目前禁用了 IIS 匿名访问,用户会使用 Windows 登录自动登录。 但是调用 User.IsInRole("Role name") 返回 false。 我仔细检查了 User.Identity.Name() 和“角色名称”,它应该返回 true。
我目前的 Web.Config 中有此内容:
更新
我在调用 User.IsInRole("Role name") 的地方应该调用 User.IsInRole("DOMAIN\Role name")
但是我仍然想知道
我应该更改什么? (是否需要
<authentication mode="Windows">
<forms
name=".ADAuthCookie"
timeout="10" />
</authentication>
<membership defaultProvider="ADMembershipProvider">
<providers>
<clear/>
<add
name="ADMembershipProvider"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ADConnectionString"
connectionUsername="XXX\specialAdUser"
connectionPassword="xx"
/>
</providers>
</membership>
<roleManager enabled="true" defaultProvider="WindowsProvider">
<providers>
<clear />
<add name="WindowsProvider" type="System.Web.Security.WindowsTokenRoleProvider" />
</providers>
</roleManager>
Very simple question actually:
I currently have IIS anonymous access disabled, users are automatically logged on using their Windows login. However calling User.IsInRole("Role name") returns false. I double-checked User.Identity.Name() and the "Role name" and it should return true.
I currently have this in my Web.Config:
UPDATE
I was calling User.IsInRole("Role name") where I should call User.IsInRole("DOMAIN\Role name")
However I still like to know if the <membership> entry is needed at all?
What should I change? (and is the <membership> entry needed at all?)
<authentication mode="Windows">
<forms
name=".ADAuthCookie"
timeout="10" />
</authentication>
<membership defaultProvider="ADMembershipProvider">
<providers>
<clear/>
<add
name="ADMembershipProvider"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ADConnectionString"
connectionUsername="XXX\specialAdUser"
connectionPassword="xx"
/>
</providers>
</membership>
<roleManager enabled="true" defaultProvider="WindowsProvider">
<providers>
<clear />
<add name="WindowsProvider" type="System.Web.Security.WindowsTokenRoleProvider" />
</providers>
</roleManager>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您使用 Windows 身份验证,IsInRole 将无需额外配置即可工作,只要您记得为角色添加域前缀,即 DOMAIN\groupName。
此外,您可以扮演(双关语)您自己的角色,并针对 SQL 角色提供程序等使用 Windows 身份验证,您不希望您的 AD 中充斥着应用程序的自定义角色。
所以不,您根本不需要提供程序配置。
If you use Windows authentication IsInRole will work with no extra configuration, as long as you remember to prefix the role with the domain, i.e. DOMAIN\groupName.
In addition you can role (pun intended) your own and use Windows auth against, for example, a SQL Role Provider, where you don't want your AD littered with custom roles for your application.
So no, you don't need the provider configuration at all.
这里的会员提供商不会提供帮助。 ActiveDirectoryMembershipProvider 似乎最适合(仅?)适合表单身份验证。
The membership provider here isn't going to help. The ActiveDirectoryMembershipProvider seems to best(only?) fit with Forms authentication.
BlogEngine.NET 有一个 Active Directory 角色提供程序。
BlogEngine.NET has an Active Directory role provider.
很确定您唯一需要的是 roleManager 组(以及基本身份验证模式='windows' 设置)
Pretty sure the only thing you need in there is the roleManager group (along with the base authentication mode='windows' setting)
开箱即用,没有角色提供程序可以直接使用 Active Directory。 您可以使用 ASP.NET 成员资格和角色系统中的角色表,也可以使用授权管理器 (AzMan)。
CodeProject 上有一篇文章,其中显示了角色提供程序的实现,该实现不利于Active Directory - 具有完整的源代码。 也许这有帮助?
马克
Out of the box, there's no role provider to use Active Directory directly. You can use the role table in the ASP.NET membership- and role-system, or you can use Authorization Manager (AzMan).
There's an article on CodeProject which shows the implementation of a role provider which works against the Active Directory - with full source code. Maybe this helps?
Marc