今天在使用enterprise library时,遇到了无法访问注册表的异常。出现的原因是asp.net运行的帐户是network service,没有对HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib 的访问权限,search了一下,找到相关的两篇文章。
http://blogs.msdn.com/chabrook/archive/2005/10/25/484813.aspxhttp://bartholomew.cnblogs.com/archive/2005/08/20/218884.aspx总结一下解决方法
1. 运行安装Enterprise Library时安装的“InstallServices.bat”批处理文件,也就是使用installutil将组件注册
2. 去掉Common工程中USEWMI、USEEVENTLOG和USEPERFORMANCECOUNTER三个编译参数,重新编译EntLib。
3. 调整Network Service和Performance Log Users 和 Performance Monitor Users的权限,使之能够访问注册表的HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib
4. 一种不能保证一定不会发生其他错误的方法,适用于当你无法更改服务器权限的情况,在web.config中的appSettings节中添加Microsoft.Practices.EnterpriseLibrary.Configuration.ConfigurationManager.ApplicationName的键值为应用程序名,主要的原因是:
After looking at the code in that PerformanceCounterInstances.CurrentInstanceName method, I noticed that they do not try to get the name of the current process using the Process.GetCurrentProcess().ProcessName property if you specify an application name with an appSettings variable in your web.config with a key of “Microsoft.Practices.EnterpriseLibrary.Configuration.ConfigurationManager.ApplicationName”.
第一种和第二种方法,我都尝试过,比较简单,