C# 在模拟打开的情况下使用当前用户上下文访问Active Directory
我正在尝试为我们的内部用户创建一个自助服务页面,通过添加/删除AD安全组中的用户来管理他们自己的文件访问 我想该网站运行的背景下,用户访问的网页,因为我们已经在广告中设置了所有的安全 我已经打开了Windows身份验证(按该顺序协商和NTLM),禁用了匿名,并在IIS 7.5中启用了模拟作为已验证用户。该站点现在在访问该页面的用户的上下文中运行(我已经使用System.Security.Principal.WindowsIdentity.GetCurrent().Name对此进行了测试) 如果我在Web服务器上的浏览器中运行该站点,它可以正常工作,但是当我从远程浏览器运行时,它在尝试运行以下代码以检索当前登录用户的安全组时返回异常C# 在模拟打开的情况下使用当前用户上下文访问Active Directory,c#,asp.net,active-directory,C#,Asp.net,Active Directory,我正在尝试为我们的内部用户创建一个自助服务页面,通过添加/删除AD安全组中的用户来管理他们自己的文件访问 我想该网站运行的背景下,用户访问的网页,因为我们已经在广告中设置了所有的安全 我已经打开了Windows身份验证(按该顺序协商和NTLM),禁用了匿名,并在IIS 7.5中启用了模拟作为已验证用户。该站点现在在访问该页面的用户的上下文中运行(我已经使用System.Security.Principal.WindowsIdentity.GetCurrent().Name对此进行了测试) 如果我
private void GetGroups()
{
// establish domain context
PrincipalContext yourDomain = new PrincipalContext(ContextType.Domain, "mydomain.com");
PrincipalSearchResult<Principal> groups = UserPrincipal.Current.GetGroups();
// if found - grab its groups
if (groups != null)
{
// iterate over all groups
foreach (Principal p in groups)
{
if (p.Name.Contains("OWNER"))
{
if (p is GroupPrincipal)
{
if (p.Name.Split('_').Length <= 5)
{
lb_folder.Items.Add(p.Name.Split('_')[3]);
}
else
{
lb_folder.Items.Add(p.Name.Split('_')[3] + "_" + p.Name.Split('_')[4]);
}
}
}
}
}
}
堆栈跟踪:
[DirectoryServicesCOMException (0x80072020): An operations error occurred.
]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +596521
System.DirectoryServices.DirectoryEntry.Bind() +44
System.DirectoryServices.DirectoryEntry.get_AdsObject() +42
System.DirectoryServices.PropertyValueCollection.PopulateList() +29
System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName) +63
System.DirectoryServices.PropertyCollection.get_Item(String propertyName) +163
System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer() +495517
System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit() +51
System.DirectoryServices.AccountManagement.PrincipalContext.Initialize() +161
System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx() +42
System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context, Type principalType, Nullable`1 identityType, String identityValue, DateTime refDate) +29
System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext context, Type principalType, IdentityType identityType, String identityValue) +146
System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context, IdentityType identityType, String identityValue) +44
System.DirectoryServices.AccountManagement.UserPrincipal.get_Current() +443
_Default.GetGroups() in c:\inetpub\wwwroot\WebSite1\Owner_fileaccess.aspx.cs:340
_Default.Button1_Click1(Object sender, EventArgs e) in c:\inetpub\wwwroot\WebSite1\Owner_fileaccess.aspx.cs:468
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +155
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3804
我了解到这可能是由于未使用Kerberos身份验证,因此我使用Fiddler检查了标题,其中显示:
标题:
WWW-Authenticate: Negotiate oYG3MIG0oAMKAQChCwYJKoZIgvcSAQICooGfBIGcYIGZBgkqhkiG9xIBAgICAG+BiTCBhqADAgEFoQMCAQ+iejB4oAMCARKicQRv8lZ872B9I6o1oV46zsl4rGFc4TZetqAXZT8VrTvMRw9ClbgTOkqlSYB6PcXxgu7Upn4UeIIEc2doa8bpd4326UitjZaU/cB021ALsaCXpGW6/wLN75pvI/tT6HrlmAuSEOsVnwZJCyR1HpS7UyKU
认证:
不知道为什么,但这只是今天开始工作,没有任何变化
我唯一能想到的是,我在AD中应用的“信任此计算机进行委派”设置需要一段时间才能复制?您是否使用了类似于:System.Security.Principal.WindowsIdentity.GetCurrent().Name;确认实际使用的上下文是否正确?尝试将其写入日志以确认。我有很多问题,我以为我在使用用户contex,但事实上它是在ASPNET上下文下运行的。是的,不幸的是我已经测试过了,我添加了一个调试文本框,并在运行时向它添加了各种内容,以便我能看到发生了什么。当通过Web服务器上的浏览器访问它时,它正在工作这一事实使我认为这是一个委托问题,但是我不知道如何进一步排除故障!
WWW-Authenticate: Negotiate oYG3MIG0oAMKAQChCwYJKoZIgvcSAQICooGfBIGcYIGZBgkqhkiG9xIBAgICAG+BiTCBhqADAgEFoQMCAQ+iejB4oAMCARKicQRv8lZ872B9I6o1oV46zsl4rGFc4TZetqAXZT8VrTvMRw9ClbgTOkqlSYB6PcXxgu7Upn4UeIIEc2doa8bpd4326UitjZaU/cB021ALsaCXpGW6/wLN75pvI/tT6HrlmAuSEOsVnwZJCyR1HpS7UyKU
No Proxy-Authenticate Header is present.
WWW-Authenticate Header (Negotiate) appears to be a Kerberos reply: