當我們嘗試在ActiveDirectory中搜索用戶時,我們得到該異常 - 0x8007203B
。System.DirectoryServices.DirectoryServicesCOMException(0x8007203B):發生本地錯誤
基本上,我們部署的Web服務,它使用DirectoryEntry
& DirectorySearcher
類找到AD用戶,而有時這種發生異常。但是當我們做IISReset時,它再次正常工作。
代碼是這樣的很簡單:
DirectoryEntry domainUser = new DirectoryEntry("LDAP://xxx.yyy/dc=xxx,dc=yyy", "domain\user", "pwd", AuthenticationTypes.Secure);
DirectoryEntry result = new DirectorySearcher(domainUser, filter);
只有一些次出現這種情況。我沒有太多的信息提供,任何猜測大加讚賞
這是我的過濾器看起來像
public static string BuildFilter(DirectoryEntry dirEntry, string userName, string userMail)
{
try
{
string filter = string.Empty;
if (!string.IsNullOrEmpty(userName) && string.IsNullOrEmpty(userMail))
filter = string.Format(@"(&(objectClass=user)(samaccounttype=805306368)(|(CN={0})(samaccountname={0})))", userName);
else if (string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(userMail))
filter = string.Format(@"(&(objectClass=user)(samaccounttype=805306368)(mail={0}))", userMail);
else
filter = string.Format(@"(&(objectClass=user)(samaccounttype=805306368)(|(CN={0})(samaccountname={0})(mail={1})))", userName, userMail);
return filter;
}
catch (Exception ex)
{
_logger.Error("BuildUserSearch - Failed to build LDAP search", ex);
}
return null;
}
向我們展示您如何設置您的DirectorySearcher!你的'過濾器'看起來像什麼?你還有什麼其他選擇? – 2011-06-09 12:40:31
@marc_s,我已經添加了過濾器代碼,並且我沒有訪問他們的安全日誌,但正如我提到的那樣,但有時連續失敗。但IISReset使它再次運作。 – Suresh 2011-06-10 04:50:10
你的.NET框架是什麼版本?有兩件事你可以嘗試:(1)在過濾器中使用'anr ='搜索參數,或者(2)移動到新的System.DirectoryServices.AccountManagement命名空間(需要.NET 3.5或更高版本),這更容易用於搜索 - 不知道它是否會修復錯誤,但:-( – 2011-06-10 04:53:32