C# 请求的注册表允许在没有安全漏洞的情况下访问
现在,我正在使用一个web应用程序,其中的代码可以从注册表读取和写入。在VisualStudio中调试时,一切正常,但在联机测试服务器上它没有运行。我收到的错误异常消息是: System.Security.SecurityException:请求的注册表访问权限无效 允许 这是我正在使用的代码:C# 请求的注册表允许在没有安全漏洞的情况下访问,c#,registry,C#,Registry,现在,我正在使用一个web应用程序,其中的代码可以从注册表读取和写入。在VisualStudio中调试时,一切正常,但在联机测试服务器上它没有运行。我收到的错误异常消息是: System.Security.SecurityException:请求的注册表访问权限无效 允许 这是我正在使用的代码: private RegistryKey GetWritableBaseRegistryKey(string extendedPath) { var path
private RegistryKey GetWritableBaseRegistryKey(string extendedPath)
{
var path = "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
return RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, RegistryView.Default).OpenSubKey($"{path}\\{extendedPath}", true);
}
我在哪里找到的解决方案:
解决方案1
您将无法将AppPoolIdentity设置为特定组,但
你可以
RegistryPermission perm1 = new RegistryPermission(RegistryPermissionAccess.AllAccess, "Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall");
perm1.Demand();
还是这个代码
RegistrySecurity rs = new RegistrySecurity();
string currentUserStr = Environment.UserDomainName + "\\" + Environment.UserName;
RegistryAccessRule accessRule = new RegistryAccessRule(currentUserStr, RegistryRights.WriteKey | RegistryRights.ReadKey | RegistryRights.Delete | RegistryRights.FullControl, AccessControlType.Allow);
rs.AddAccessRule(accessRule);
但是这些在服务器上不起作用,但是在VisualStudio中调试时,代码运行良好
为了让web应用程序访问注册表,它必须具有足够的权限。因此,解决方案1是唯一可能起作用的方案。它描述了将网站应用程序池设置为本地administrators组中的用户。它忽略了将IIS网站实际设置为使用新创建的应用程序池的步骤,这就是为什么它可能不适合您的原因 在web服务器中读取受限注册表的技术过程,尤其是应用程序卸载注册表项,对您来说不太可能有用。允许web服务器访问服务器自己的应用程序卸载列表有什么可能的用途
我怀疑您打算在客户端的PC上打开该注册表项(我的猜测),这是不可能的。您只是不。。。。为什么您甚至需要访问web应用程序中的注册表?(感觉)旁注:我认为他们得到的错误来自.Net CAS,而不是Windows级别的安全检查,所以他们可能需要1+3(Windows权限和.Net
需求
)来托管web应用程序。。。