在我的ASP.NET Web应用程序中,My.Computer.Registry.SetValue(Key_Name,Value_Name,Metric)导致"access to registry key is denied"错误 .
应用程序正在Azure Windows Server 2012 VM上运行 . 但是,我的.NET Windows应用程序也运行在同一个VM上,写入注册表确定 .
我试过设置regedit>关键:对每个人=完全控制,仍然被拒绝 .
我在同一台计算机上的.NET Windows应用程序(Azure Windows Server 2012 R2)写入注册表项“HKEY_CURRENT_USER \ Software \”&SOFTWARE_PROGRAM_NAME _&“\ Metrics \”&Key_Name没有问题 .
这是导致问题的ASP.NET代码...... ......... ..
' Set the key address within the System Registry:
Key_Name = "HKEY_CURRENT_USER\Software\" & SOFTWARE_PROGRAM_NAME _
& "\Metrics\" & Key_Name
Metric = My.Computer.Registry.GetValue(Key_Name, Value_Name, 0) ' read present value
if metric_function = 1
metric = 0
else if metric_function = 2
Metric = metric_value
else
Metric += 1 ' increment it
End If
My.Computer.Registry.SetValue(Key_Name, Value_Name, Metric) ' store new value
当我浏览我的ASP.NET WEB时,这是错误的.....
Server Error in '/' Application.
Access to the registry key 'HKEY_CURRENT_USER\Software\myApp\Metrics\WEB Communication' is denied.
Exception Details: System.UnauthorizedAccessException: Access to the registry key 'HKEY_CURRENT_USER\Software\Pray\Metrics\WEB Communication' is denied.
Source Error:
Line 152: Metric += 1 ' increment it
Line 153: End If
Line 154: My.Computer.Registry.SetValue(Key_Name, Value_Name, Metric) ' store new value
Line 155:
Line 156: ' Update the metrics display in the control pane:
Source File: C:\PRIMARY\INTERNET\APPS\DEPLOYED\myApp\myApp web\App_Code\Metrics.vb Line: 154
Stack Trace:
[UnauthorizedAccessException: Access to the registry key 'HKEY_CURRENT_USER\Software\myApp\Metrics\WEB Communication' is denied.]
Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str) +144
Microsoft.Win32.RegistryKey.CreateSubKeyInternal(String subkey, RegistryKeyPermissionCheck permissionCheck, Object registrySecurityObj, RegistryOptions registryOptions) +14824601
Microsoft.Win32.RegistryKey.CreateSubKey(String subkey) +25
Microsoft.Win32.Registry.SetValue(String keyName, String valueName, Object value, RegistryValueKind valueKind) +78
Microsoft.VisualBasic.MyServices.RegistryProxy.SetValue(String keyName, String valueName, Object value) +48
Metrics.inc(Object& Key_Name, Object& Value_Name, Object metric_function, Object metric_value) in C:\PRIMARY\INTERNET\APPS\DEPLOYED\myApp\myApp web\App_Code\Metrics.vb:154
Metrics.Communication(Object& Value_Name, Object reset_metric) in C:\PRIMARY\INTERNET\APPS\DEPLOYED\myApp\myApp web\App_Code\Metrics.vb:88
_Default.Page_Load(Object sender, EventArgs e) in C:\PRIMARY\INTERNET\APPS\DEPLOYED\myApp\myApp web\Default.aspx.vb:142
System.Web.UI.Control.OnLoad(EventArgs e) +103
System.Web.UI.Control.LoadRecursive() +68
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1381