5

我在我的一个应用程序中遇到了一个错误,该错误每月发生几次,但本周发生了两次。发生这种情况时,总是在早上第一个用户加载应用程序并开始工作(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;
            }
        }
    }

所以这个问题密切相关,但我的权限设置正确,代码 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)

问题可能是什么?内存泄漏?常见的模式是,当第一个用户开始使用应用程序时,这会发生在早上的第一件事。

4

2 回答 2

1

我们有一个类似的问题。这是微软提供的解决方案。我希望这可以帮助别人。

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) 中找到

计算机配置->管理模板->系统->用户配置文件

不要在用户注销时强制卸载用户注册表

将设置从“未配置”更改为“启用”,这将禁用新的用户配置文件服务功能。

这种变化不应该有任何副作用。

于 2019-11-05T19:20:46.390 回答
0

很长一段时间以来,我一直在为完全相同的问题苦苦挣扎。我的解决方案实际上是安装功能IIS 6 Metabase Compatblity。之后就没有问题了。一些对我有帮助的文章如下

http://blogs.msdn.com/b/jpsanders/archive/2009/05/13/iis-7-adsi-error-system-runtime-interopservices-comexception-0x80005000-unknown-error-0x80005000.aspx

http://michaelwasham.com/2011/04/25/annoying-error-using-system-directoryservices-and-iis-app-pools/

于 2015-03-20T14:26:54.757 回答