当请求来自web服务器时,运行在IIS7.5上的ASP.NET WebForms应用程序可以正常工作,但当同一个域用户从域中的任何其他计算机请求相同的页面时,会引发以下错误:
类型: System.DirectoryServices.AccountManagement.PrincipalOperationException MSG:发生了操作错误。 在System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInit() at System.DirectoryServices.AccountManagement.PrincipalContext.DoDomainInit() at System.DirectoryServices.AccountManagement.PrincipalContext.Initialize() at System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx() at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context,在System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext上下文中键入principalType、Nullable`1‘1 identityType、String identityValue、DateTime refDate),在System.DirectoryServices.AccountManagement.GroupPrincipal.FindByIdentity(PrincipalContext上下文中键入principalType、String identityValue),Ceoimage.Basecamp.ActiveDirectory.SidSource._TryGetGroupPrincipal(PrincipalContext上下文中的字符串identityValue( String identityValue),在c:\Users\David\Documents\VsProjects\CeoTrunk\Ceoimage.Basecamp\Basecamp\ActiveDirectory\SidSource.cs:line 115中的字符串groupName) -内在例外-- 类型: System.DirectoryServices.DirectoryServicesCOMException MSG:发生了操作错误。 (在System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) ( System.DirectoryServices.DirectoryEntry.Bind() at System.DirectoryServices.DirectoryEntry.get_SchemaEntry() at System.DirectoryServices.AccountManagement.ADStoreCtx.IsContainer(DirectoryEntry de) ( System.DirectoryServices.AccountManagement.ADStoreCtx..ctor(DirectoryEntry ctxBase )布尔ownCtxBase字符串用户名字符串密码ContextOptions选项( System.DirectoryServices.AccountManagement.PrincipalContext.CreateContextFromDirectoryEntry(DirectoryEntry entry) (System.DirectoryServices.AccountManagement.PrincipalContext.CreateContextFromDirectoryEntry(DirectoryEntry entry)
应用程序的web.config文件指定<authentication mode="Windows">
和<identity impersonate="true" />
,但不使用成员资格提供程序。在IIS中,应用程序池以域用户的身份运行,应用程序的身份验证已经禁用,除了ASP.NET模拟(设置为经过身份验证的用户)和之外。
导致错误的代码只是尝试获取组的SID以验证用户应该访问应用程序:
public string GetGroupSid()
{
using (var context = new PrincipalContext("Domain", "Test", "CN=Users,DC=Test,DC=local", ContextOptions.Negotiate))
{
var group = _TryGetGroupPrincipal(context, "AppGroup");
return group.Sid.Value;
}
}
private static GroupPrincipal _TryGetGroupPrincipal(PrincipalContext context, string groupName)
{
try
{
return GroupPrincipal.FindByIdentity(context, groupName);
}
catch (Exception e)
{
throw _GetUnableToFindGroupException(e, groupName);
}
}
如前所述,如果请求来自web服务器,则应用程序可以正常工作,但当同一个域用户从域上的任何其他计算机请求相同的页面时,该应用程序会抛出此错误。我知道启用Kerberos,但您可以看到我的代码指定了ContextOptions.Negotiate
。我不是这方面的专家,但我很难理解。
发布于 2011-10-14 14:46:32
为委托配置web服务器允许我的web应用程序查询AD组的SID,没有错误,也不需要更改任何代码。
https://stackoverflow.com/questions/7760158
复制相似问题