我的一个应用程序出现错误,每个月发生几次,但本周发生了两次。当这种情况发生时,第一个用户加载应用程序并开始工作时,它总是第一件事(Web应用程序,3-4个内部用户)错误源于这个非常简单的方法,一旦失败,它将无法工作,直到我重启应用程序池。现在,我也在以其他方式查询AD,但这是第一个与用户在早上开始工作时调用的AD相关方法。
public DomainUser GetDomainUser(string userLoginName)
{
using (PrincipalContext context = new PrincipalContext(ContextType.Domain, this.DomainName))
{
using (UserPrincipal user = UserPrincipal.FindByIdentity(context, userLoginName))
{
// If user is null, the result is not a UserPrinciple
if (user != null)
{
string firstName = user.GivenName;
string middleName = user.MiddleName;
string lastName = user.Surname;
int empId = Convert.ToInt32(user.EmployeeId);
string emailAddr = user.EmailAddress;
string userName = user.SamAccountName;
DateTime? accountExp = user.AccountExpirationDate;
return new DomainUser
{
FirstName = firstName,
MiddleName = middleName,
LastName = lastName,
EmployeeId = empId,
Email = emailAddr,
UserName = userName,
AccountExpiration = accountExp
};
}
return null;
}
}
}
所以this问题密切相关,但我的权限设置正确,代码可以99%的时间运行,并会在应用程序池重启后继续运行。
堆栈跟踪看起来像这样:
System.Runtime.InteropServices.COMException (0x80005000): Unknown error (0x80005000)
at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
at System.DirectoryServices.DirectoryEntry.Bind()
at System.DirectoryServices.DirectoryEntry.get_AdsObject()
at System.DirectoryServices.PropertyValueCollection.PopulateList()
at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName)
at System.DirectoryServices.PropertyCollection.get_Item(String propertyName)
at System.DirectoryServices.AccountManagement.PrincipalContext.DoLDAPDirectoryInitNoContainer()
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, Type principalType, Nullable`1 identityType, String identityValue, DateTime refDate)
at System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext context, Type principalType, String identityValue)
at System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context, String identityValue)
at ADWrapper.AdSearch.GetDomainUser(String userLoginName)
问题是什么?内存泄漏?常见的模式是,当第一个用户开始使用应用程序时,这首先发生在早上。
答案 0 :(得分:0)
我在很长一段时间里一直在努力解决同样的问题。我的解决方案实际上是安装功能 IIS 6 Metabase Compatiblity 。之后没有问题。一些帮助我的文章在
之下http://michaelwasham.com/2011/04/25/annoying-error-using-system-directoryservices-and-iis-app-pools/
答案 1 :(得分:0)
我们遇到了类似的问题。这是Microsoft提供的解决方案。我希望这对某人有帮助。
DirectoryEntry.Bind函数最终调用ADsOpenObject(https://docs.microsoft.com/en-us/windows/win32/api/adshlp/nf-adshlp-adsopenobject) 此功能有一个“路由器”。路由器的初始化从注册表中枚举了提供程序,例如“ LdapNamespace”。该文件位于HKEY_CLASSES_ROOT \ CLSID {228D9A82-C302-11cf-9AA4-00AA004A5691} \ ProgID。 其他提供程序(例如WinNT名称空间)也被枚举。
在跟踪中,查找这些注册表项时将返回错误。错误是
ERROR_KEY_DELETED
1018(0x3FA)
尝试对已标记为删除的注册表项进行非法操作。
此错误可能是由于卸载该进程用于其标识的用户配置文件引起的。
Windows用户配置文件服务会强制卸载用户配置文件。这会导致该过程出现问题。
我已经通过w3wp.exe和dllhost.exe看到了这一点,在此之前,注册表配置文件在此过程完成之前已被卸载。
这是我们针对dllhost.exe问题写的博客:https://blogs.msdn.microsoft.com/distributedservices/2009/11/06/a-com-application-may-stop-working-on-windows-server-2008-when-the-identity-user-logs-off/
您可能会在应用程序日志中看到警告,描述如下: Windows检测到您的注册表文件仍被其他应用程序或服务使用。该文件将立即被卸载。包含注册表文件的应用程序或服务此后可能无法正常运行。
我认为我们应该在博客中尝试解决方法/解决方法:
决议
作为解决方法,可能有必要禁用此功能,这是默认行为。策略设置“在用户注销时不强制卸载用户注册表”会抵消Windows 2008的默认行为。启用后,Windows 2008不会强制卸载注册表,并等待直到没有其他进程在使用用户注册表后再卸载它。
该策略可以在组策略编辑器(gpedit.msc)中找到
计算机配置->管理模板->系统-> UserProfiles
请勿在用户注销时强行卸载用户注册表
将设置从“未配置”更改为“启用”,这将禁用新的用户配置文件服务功能。
此更改不应有任何副作用。