私たちは、誰もがこのややランダムなエラーを経験するチームです。エラーは以下にリストされており、次の行に表示されます: UserPrincipal.FindByIdentity(principalContext, windowsPrincipal.Identity.Name);
数日/数週間/数か月は問題なく動作しますが、そのうちの 1 人がこのエラーを受け取ります。
ローカル マシンほど頻繁に変更をデプロイしないテスト サーバーでは、このエラーが発生するまで何ヶ月も動作します。
アプリケーション プールを ApplicationPoolIdentity から NetworkService に変更すると、うまくいきます。ただし、ApplicationPoolIdentity に戻すと、同じエラーが表示されます。
IISreset は役に立ちません。
コンピューターを再起動すると常に問題が解決するため、ApplicationPoolIdentity は日常的に私たちを認証するのに問題はありません。
これは、使用するコード (多少変更されています) です。
var windowsPrincipal = principal as WindowsPrincipal;
if (windowsPrincipal == null)
return null;
try
{
var principalContext = new PrincipalContext(ContextType.Domain);
var userPrincipal = UserPrincipal.FindByIdentity(principalContext, windowsPrincipal.Identity.Name);
if (userPrincipal == null) return null;
return userPrincipal.Surname;
}
エラーメッセージは次のとおりです。
An operations error occurred.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.DirectoryServices.DirectoryServicesCOMException: An operations error occurred.
Source Error:
var principalContext = new PrincipalContext(ContextType.Domain);
var userPrincipal = UserPrincipal.FindByIdentity(principalContext, windowsPrincipal.Identity.Name);
Stack Trace:
[DirectoryServicesCOMException (0x80072020): An operations error occurred.
]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +628309
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() +521413
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.UserPrincipal.FindByIdentity(PrincipalContext context, String identityValue) +81