C# 使用 Active Directory 中的安全组的 Asp.Net 基于角色的身份验证
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/209242/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Asp.Net Role-based authentication using Security groups in Active Directory
提问by Kolten
I am attempting to do something simple (I thought) - securing my application using roles-based security using Active Directory groups in our Domain.
我正在尝试做一些简单的事情(我认为) - 使用我们域中的 Active Directory 组使用基于角色的安全性来保护我的应用程序。
Specifically, I need to show/hide items on a page depending upon whether the currently logged in user is part of domain\groupAin Active Directory. For some reason, it is difficult finding information on using Active Directory for this. Everything I seem to find goes into details of using forms-based authentication using roles, or it uses a DB to store the information.
具体来说,我需要根据当前登录的用户是否属于domain\groupAActive Directory来显示/隐藏页面上的项目。出于某种原因,很难找到有关为此使用 Active Directory 的信息。我似乎发现的所有内容都涉及使用角色的基于表单的身份验证的详细信息,或者它使用数据库来存储信息。
All I want to do is use our already outlined security structure in our Active Directory. Can someone please explain what I need?
我想要做的就是在我们的 Active Directory 中使用我们已经概述的安全结构。有人可以解释一下我需要什么吗?
Do I need:
我需要:
<roleManager enabled="true"/>inweb.config<allow roles ="domain\groupA"/>inweb.config- IIS set to windows authentication
if (User.IsInRole(@"domain\groupA")){ //do stuff }in my page?
<roleManager enabled="true"/>在web.config<allow roles ="domain\groupA"/>在web.config- IIS 设置为 Windows 身份验证
if (User.IsInRole(@"domain\groupA")){ //do stuff }在我的页面?
What else am I missing? Anything? 'cause its not working. heh.
我还缺少什么?任何事物?因为它不工作。呵呵。
Thanks all for your help.
感谢你的帮助。
采纳答案by tvanfosson
You probably just need to add a RoleProvider to your web.config to tell the app how to do searches against AD.
您可能只需要向您的 web.config 添加一个 RoleProvider 来告诉应用程序如何针对 AD 进行搜索。
Sample code from here.
来自此处的示例代码。
<roleManager defaultProvider="WindowsProvider"
enabled="true"
cacheRolesInCookie="false">
<providers>
<add
name="WindowsProvider"
type="System.Web.Security.WindowsTokenRoleProvider" />
</providers>
</roleManager>

