![](/img/trans.png)
[英]Cannot read all users from Active Directory - [DirectoryServicesCOMException] MoveNext()
[英]Why does DirectoryServicesCOMException occur querying Active Directory from a machine other than the web server?
當請求來自Web服務器時,在IIS 7.5上運行的ASP.NET WebForms應用程序正常工作,但當同一域用戶從域上的任何其他計算機請求同一頁面時,會引發以下錯誤:
TYPE: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 System.DirectoryServices上的System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext context,Type principalType,String identityValue)中的.DirectoryServices.AccountManagement.Principal.FindBdentIdentityWithTypeHelper(PrincipalContext context,Type principalType,Nullable`1 identityType,String identityValue,DateTime refDate) .AcountManagement.GroupPrincipal.FindByIdentity(PrincipalContext context,String identityValue)位於c:\\ Users \\ David \\ Documents \\ VsProjects \\ CeoTrunk \\ Ceoimage.Basecamp \\ Basecamp \\中的Ceoimage.Basecamp.ActiveDirectory.SidSource._TryGetGroupPrincipal(PrincipalContext context,String groupName) ActiveDirectory中\\ SidSource.cs :第115行
- 內部例外 -
TYPE:System.DirectoryServices.DirectoryServicesCOMException
MSG:發生了操作錯誤。
在System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)位於System.DirectoryServices.DirectoryEntry.Bind()的System.DirectoryServices.DirectoryEntry.get_SchemaEntry()處於System.DirectoryServices.AccountManagement.ADStoreCtx.IsContainer(DirectoryEntry de)的System.DirectoryServices上.AccountManagement.ADStoreCtx..ctor(DirectoryEntry ctxBase,Boolean ownCtxBase,String username,String password,ContextOptions選項)位於System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInit()的System.DirectoryServices.AccountManagement.PrincipalContext.CreateContextFromDirectoryEntry(DirectoryEntry條目)中。
應用程序的web.config文件指定<authentication mode="Windows">
和<identity impersonate="true" />
但不使用成員資格提供程序。 在IIS中,應用程序池作為域用戶運行,除了ASP.NET模擬(設置為Authenticated用戶)和Windows身份驗證之外,應用程序的身份驗證已禁用所有內容。
導致錯誤的代碼只是嘗試獲取組的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
。 我不是這方面的專家,但我對此感到困惑。
配置Web服務器以進行委派允許我的Web應用程序無錯誤地查詢AD組的SID,並且不更改任何代碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.