2014-02-21 46 views
1

我最近将应用程序从使用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 

我也是得到(似乎是随机的)错误交谈Active Directory时:

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今天没给我答案。

+0

当我调用'Domain.GetComputerDomain()'时,如果我没有足够的权限,或者'Load User Profile'关闭时_maybe_被调用,我得到'已经标记为删除的注册表项上的非法操作'。因此,有时在访问域/用户信息时,它似乎是一个报告严重的权限问题。给予管理员权利似乎可以解决这个问题。 – Rory

回答

3

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

更改应用程序池设置Load User ProfileTrue解决了问题并且事件日志条目停止发生。

0

我打算试一试,并说你可能没有正确清理资源。 Microsoft.Win32.RegistryKey对象和System.DirectoryServices.AccountManagement.PrincipalContext均为IDisposable,并且在不再使用时必须予以处置。

当用户的会话在更改之前超时时,可能会清理这些资源,并且因为您已关闭模拟,所以这些资源已不再可用。

+0

感谢您的回复。我在代码中不常使用'System.DirectoryServices',但我确实经历过寻找没有处理的对象,而且我没有发现该代码存在问题。还有一点需要注意的是,我有多个应用程序池以相同的服务帐户身份运行。是否值得发布我的少量目录代码? –

相关问题