来自Active Directory的间歇性未知错误

时间:2016-03-28 09:51:45

标签: c# asp.net .net active-directory directoryservices

我正在使用.Net帐户管理库来访问Active Directory以搜索当前http请求用户的详细信息。 我的应用程序池使用自定义帐户运行,也来自同一个域。服务器和用户也属于同一个域。

public string GetEmployeeId(string SAMAccountName)
{
using (PrincipalContext domainContext = new PrincipalContext(ContextType.Domain))
{
using (UserPrincipal userprincipal = new UserPrincipal(domainContext))
{
userprincipal.SamAccountName = SAMAccountName; 
using (PrincipalSearcher ps = new PrincipalSearcher()) 
{
ps.QueryFilter = userprincipal; 
UserPrincipal user = ps.FindOne() as UserPrincipal;
return user.EmployeeId; 
}
}
}
}

设置完全间歇性地我从AD获得以下错误。有时它适用于同一用户而没有任何错误

有没有办法检查来自AD端的日志/事件,以找出导致此错误的原因。

  

System.Runtime.InteropServices.COMException(0x80005000):未知错误>(0x80005000)

2 个答案:

答案 0 :(得分:2)

我与Microsoft工程师合作了很长时间来解决此问题,因此希望我的解决方案可以帮助其他人解决他们的问题。

首先将错误代码0x80005000引荐来源网址传递给无效的ADSI路径名,但这并不是特别有用。

我们进行了很多跟踪,这也不是很有帮助。我们要做的最后一件事是使用Process Monitor来跟踪注册表。

发生错误时,我注意到发生了HIVE UNLOADED结果(请参见屏幕截图) trace shot

基于此,我们还发现此错误出现在事件日志中。

Log Name:      Application 
Source:        Microsoft-Windows-User Profiles Service 
Date:          10/26/2009 8:22:13 AM 
Event ID:      1530 
Task Category: None 
Level:         Warning 
Keywords:      Classic 
User:          SYSTEM 
Computer:      SERVERNAME 
Description: 
Windows detected your registry file is still in use by other applications or services. The file will be unloaded now. The applications or services that hold your registry file may not function properly afterwards.  
DETAIL - 
1 user registry handles leaked from \Registry\User\S-1-5-21-1049297961-3057247634-349289542-1004_Classes: 
Process 2428 (\Device\HarddiskVolume1\Windows\System32\dllhost.exe) has opened key \REGISTRY\USER\S-1-5-21-1123456789-3057247634-349289542-1004_CLASSES

工程师建议本文https://support.microsoft.com/en-us/help/2287297/a-com-application-may-stop-working-on-windows-server-2008-when-a-user

这似乎可以解决我的问题。

答案 1 :(得分:-1)

尝试确定您将使用的域名服务器:

像:   = new PrincipalContext(ContextType.Domain,“YOURADDOMAIN”);