【问题标题】:Using application pool identity results in exceptions and event logs使用应用程序池标识会导致异常和事件日志
【发布时间】:2014-02-21 17:32:06
【问题描述】:

我最近将我的应用程序从使用 ASP.NET 模拟转换为在应用程序池中实际指定身份。这样做的原因是为了让将来更容易使用async,以便线程作为我的服务帐户运行。

自从进行更改后,该网站遇到了一些问题。在我进行更改的那天,我现在看到这些事件日志出现的频率更高(过去是每天 2-3 次,现在是每天 8-10 次):

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 - 
 3 user registry handles leaked from \Registry\User\S-1-5-21-1695807550-3099950144-3292890465-4346:
Process 3840 (\Device\HarddiskVolume2\Windows\System32\inetsrv\w3wp.exe) has opened key \REGISTRY\USER\S-1-5-21-1695807550-3099950144-3292890465-4346
Process 3840 (\Device\HarddiskVolume2\Windows\System32\inetsrv\w3wp.exe) has opened key \REGISTRY\USER\S-1-5-21-1695807550-3099950144-3292890465-4346\Control Panel\International
Process 3840 (\Device\HarddiskVolume2\Windows\System32\inetsrv\w3wp.exe) has opened key \REGISTRY\USER\S-1-5-21-1695807550-3099950144-3292890465-4346\Software\Microsoft\Windows\CurrentVersion\Explorer

在与活动目录交谈时,我也收到(似乎是随机的)错误:

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, IdentityType identityType, String identityValue)
   at System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context, IdentityType identityType, String identityValue)

我在进行更改后看到的最后一个错误(尽管它似乎不太经常发生):

System.Runtime.InteropServices.COMException (0x800703FA): Illegal operation attempted on a registry key that has been marked for deletion.

   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, IdentityType identityType, String identityValue)
   at System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context, IdentityType identityType, String identityValue)

一旦我重置应用程序池,问题就会消失。不幸的是,它似乎在一两天后又回来了。

有人知道这里有什么吗?我可以重新使用模拟,因为在我将应用程序池身份切换为特定用户之前,这种情况从未发生过。我的 Google-fu 今天没有给我任何答案。

【问题讨论】:

  • 如果我没有足够的权限,我在调用Domain.GetComputerDomain() 时得到Illegal operation attempted on a registry key that has been marked for deletion,或者当Load User Profile 关闭时可能。因此,在访问域/用户信息时,有时似乎是一个错误报告的权限问题。授予管理员权限似乎可以解决此问题。

标签: c# asp.net-mvc iis active-directory iis-7.5


【解决方案1】:

我无法找到问题的根本原因。但是,如果底层代码依赖于属于该身份的资源,似乎对多个应用程序池使用相同的身份可能会导致一些问题。

将应用程序池设置 Load User Profile 更改为 True 修复了问题并且事件日志条目停止发生。

【讨论】:

    【解决方案2】:

    我将对此进行尝试,并说您可能没有正确清理资源。 Microsoft.Win32.RegistryKey 对象和 System.DirectoryServices.AccountManagement.PrincipalContext 都是 IDisposable 并且在不再使用时必须丢弃。

    当用户的会话在更改之前超时时,这些资源可能已被清理,而在您关闭模拟后它们不再存在。

    【讨论】:

    • 感谢您的回复。我在我的代码中不经常使用System.DirectoryServices,但我确实通过寻找我没有处理的对象并且我没有发现该代码的问题。另一个注意事项是,我有多个应用程序池以相同的服务帐户身份运行。也值得发布我的少量目录代码吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-17
    • 1970-01-01
    • 1970-01-01
    • 2021-05-24
    • 2011-10-03
    • 1970-01-01
    • 2014-11-25
    相关资源
    最近更新 更多