什么时候发生ASP.NET身份验证?
问题描述:
我有一个应用程序,可以显示当前用户所属的每个Active Directory组。当我的配置设置如下:什么时候发生ASP.NET身份验证?
<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)));
}
答
我可能是错的,但我相信这是它如何工作的:
第一次浏览器点击网站它是匿名的。
如果服务器说不允许匿名,浏览器会发送用户的Windows凭据。
如果这些凭证不通过召集,那么浏览器会弹出登录框或(取决于应用程序)将它们发送到登录页面。
因此,因为您的网站允许匿名,所有用户都以这种方式进入。
尽管我无法确认或否认,但在没有必要进行身份验证时,它似乎是一种合理的优化,无需对用户进行身份验证。 – Lazarus 2010-11-30 16:29:28
User.Identity.Name在失败时是否有值? – Zachary 2010-11-30 16:38:36