【发布时间】:2010-11-30 16:25:15
【问题描述】:
我有一个应用程序,其中显示了当前用户所属的每个 Active Directory 组。当我有这样的配置设置时:
<authentication mode="Windows"/>
<authorization>
<deny users="?"/>
<allow users="*"/>
</authorization>
它工作正常。当它是这样的:
<authentication mode="Windows"/>
<authorization>
<!--<deny users="?"/>-->
<allow users="*"/>
</authorization>
未找到任何组。为什么这会有所作为? asp.net 是否仅在我们明确拒绝未经身份验证的用户访问时才进行身份验证?
如果有帮助,这就是我获取群组的方式:
protected string GetUserGroups()
{
StringBuilder userGroups = new StringBuilder();
ArrayList groupMembers = new ArrayList();
DirectoryEntry root = new DirectoryEntry("LDAP://myldap/DC=nc,DC=local");
DirectorySearcher ds = new DirectorySearcher(root);
ds.Filter = String.Format("(&(samaccountname={0})(objectClass=person))", User.Identity.Name.Substring(User.Identity.Name.LastIndexOf(@"\") + 1));
ds.PropertiesToLoad.Add("memberof");
try
{
foreach (SearchResult sr in ds.FindAll())
{
foreach (string str in sr.Properties["memberof"])
{
string str2 = str.Substring(str.IndexOf("=") + 1, str.IndexOf(",") - str.IndexOf("=") - 1);
groupMembers.Add(str2);
}
}
}
catch
{
//ignore if any properties found in AD
}
return String.Join("|", (string[])groupMembers.ToArray(typeof(string)));
}
【问题讨论】:
-
虽然我无法确认或否认,但在不需要身份验证时不对用户进行身份验证似乎是一种合理的优化。
-
User.Identity.Name 失败时是否有值?
-
如果您允许匿名访问,Asp.net 不需要身份验证。真的,如果其他用户不发送,为什么我必须发送我的用户名?他比我好吗?您可以在 global.asax 事件中设置断点来确保这一点。
-
我不确定您所说的“如果其他用户不发送我的用户名,为什么我必须发送我的用户名?”评论。我不关心用户名以及用户是否属于任何组,我想知道哪些组。
标签: asp.net security active-directory