简体   繁体   English

如何启用 ASP.NET 对注册表项“HKEY_CURRENT_USER\\Software\\myAppKey\\subdir”的写访问权限?

[英]How to enable ASP.NET write access to the registry key 'HKEY_CURRENT_USER\Software\myAppKey\subdir'?

In my ASP.NET web app My.Computer.Registry.SetValue(Key_Name, Value_Name, Metric) causes "access to registry key is denied" error.在我的 ASP.NET Web 应用程序中 My.Computer.Registry.SetValue(Key_Name, Value_Name, Metric) 导致“访问注册表项被拒绝”错误。
App is running on Azure Windows Server 2012 VM.应用程序在 Azure Windows Server 2012 VM 上运行。 However, my .NET windows app also running on same VM, writes to registry ok.但是,我的 .NET Windows 应用程序也在同一 VM 上运行,可以正常写入注册表。

I've tried setting regedit > the key: to everyone=full control, still denied.我试过设置 regedit > the key: toeveryone=full control,仍然被拒绝。

My .NET windows app on same computer (Azure Windows Server 2012 R2) writes to registry key "HKEY_CURRENT_USER\\Software\\" & SOFTWARE_PROGRAM_NAME _ & "\\Metrics\\" & Key_Name without problem.我在同一台计算机(Azure Windows Server 2012 R2)上的 .NET Windows 应用程序写入注册表项“HKEY_CURRENT_USER\\Software\\”& SOFTWARE_PROGRAM_NAME _ & “\\Metrics\\” & Key_Name 没有问题。

HERE IS ASP.NET CODE THAT CAUSES PROBLEM...………..这是导致问题的 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

HERE IS ERROR WHEN I BROWSE MY ASP.NET WEB.....这是我浏览 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

You go to your IIS pool, open advanced properties.您转到 IIS 池,打开高级属性。 There you probably see some default identity selected as identity for your pool.在那里您可能会看到一些默认身份被选为池的身份。 There you need to set an identity that has permissions to access file system and correspondingly, the registry.在那里,您需要设置一个有权访问文件系统和相应注册表的身份。 I usually create a local user with admin rights and permanent password, and then use that local admin as identity for my IIS apps.我通常创建一个具有管理员权限和永久密码的本地用户,然后使用该本地管理员作为我的 IIS 应用程序的标识。 This way I don't worry if app needs to write a file, etc这样我就不用担心应用程序是否需要写入文件等

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 拒绝访问注册表项'HKEY_CURRENT_USER \\ Software \\ Policies \\ Microsoft \\ office \\ 15.0 \\ outlook' - Access to the registry key 'HKEY_CURRENT_USER\Software\Policies\Microsoft\office\15.0\outlook' is denied 将注册表写入hkey_current_user而不是hkey_users - write registry to hkey_current_user instead of hkey_users 如何将注册表根键的快捷方式/速记/缩写扩展为全名,如 HKCU 到 HKEY_CURRENT_USER? - How to expand shortcut / shorthand / abbreviation for registry root key to full name, like HKCU to HKEY_CURRENT_USER? 无法写入HKEY_CURRENT_USER - Unable to write to HKEY_CURRENT_USER winform C#,不确定为什么要修改HKEY_CURRENT_USER注册表项 - winform c#, Unsure why HKEY_CURRENT_USER registry key modification is requiring elevation HKEY_CURRENT_USER不会发生注册表重定向 - Registry redirection does not happen for HKEY_CURRENT_USER 如何允许非管理员用户写入注册表项HKEY_LOCAL_MACHINE \\ SOFTWARE \\ SWname \\ Licenses - How to allow non-admin user to write to registry key HKEY_LOCAL_MACHINE\SOFTWARE\SWname\Licenses 无法在C#中写入HKEY_CURRENT_USER注册表项 - Can't write to HKEY_CURRENT_USER registrykey in C# 从注册表读取HKEY_CURRENT_USER的子项将返回HKEY_USERS子项的值 - Reading subkeys of HKEY_CURRENT_USER from Registry returns HKEY_USERS subkeys value 如何从 WinUI3 C# 应用程序写入 HKEY_CURRENT_USER\\Control Panel\\Desktop\\WindowMetrics - How to write to HKEY_CURRENT_USER\\Control Panel\\Desktop\\WindowMetrics from WinUI3 C# app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM