我有一个Intranet Web应用程序,其中加密的连接字符串存储在Windows注册表中(连接字符串由其他一些应用程序共享)。应用程序托管在Windows 2012服务器上。在开发/测试环境(非生产)中,我希望能够修改此密钥,以便切换到不同的数据库。
我似乎无法写信给我,根据我的处理方式不断出现不同的错误:
string sKeyValue = "SOFTWARE\\SomeProject\\SomeApp";
RegistryKey rk;
rk = Registry.LocalMachine.OpenSubKey(sKeyValue, true); // Requested registry access is not allowed.
尝试:
RegistryPermission p = new RegistryPermission(RegistryPermissionAccess.AllAccess, sKeyValue);
p.Assert();
也
RegistrySecurity rs = new RegistrySecurity();
RegistryKey key = Registry.LocalMachine;
rs = key.GetAccessControl();
string sUser = @"domain\userid";
rs.AddAccessRule(new RegistryAccessRule(sUser, RegistryRights.WriteKey, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow));
key.SetAccessControl(rs); //Exception: "Attempted to perform an unauthorized operation."
答案 0 :(得分:0)
允许从Web应用程序对注册表进行写访问只是一个坏主意。通过Web代码自动设置权限是危险的,并且要求代码具有过高的权限。
最好让所有网络应用程序都能从同一个web.config文件中读取,然后获取类似于此处所述的共享设置。