加密和使用中等信任在web.config中保存ASP.NET的ConnectionString? [英] Encrypt and Save the ASP.NET ConnectionString within the web.config using Medium Trust?

查看:288
本文介绍了加密和使用中等信任在web.config中保存ASP.NET的ConnectionString?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已搜查周围谷歌和#1,但不能看到拿出编辑web.config中加密和存储安装脚本SQL Server连接字符串的解决方案。

I have searched around Google and Stackoverflow but can't seen to come up with a solution for editing the web.config to encrypt and store a SQL Server connection string for an installation script.

在<一个链接href=\"http://our.umbraco.org/forum/ourumb-dev-forum/bugs/3569-Acessing-the-webconfig-in-Medium-trust\"相对=nofollow>访问在中等信任web.config中似乎表明以下code会工作,而不是OpenWebConfiguration的,然而,这是不是在本地开发服务器上运行(运行中等信任)或在Rackspace公司云(原莫索)。

The link at Accessing the web.config in Medium trust seems to suggest that the following code would work instead of OpenWebConfiguration, however this is not working on the local development server (running Medium Trust) or at Rackspace Cloud (formerly Mosso).

String cfgpath = Server.MapPath(@"/web.config");
cfg = System.Configuration.ConfigurationManager.OpenExeConfiguration(cfgpath);

Rackspoace云可以设置保存使用假冒文件,但我仍然收到发生错误加载配置文件:请求类型的权限'System.Security.Permissions.FileIOPermission捕捉ConfigurationErrorsException时错误。

Rackspoace Cloud can be setup to save files using Impersonation, however I am still receiving the "An error occurred loading a configuration file: Request for the permission of type 'System.Security.Permissions.FileIOPermission" error when catching the ConfigurationErrorsException.

任何想法我怎么能编辑web.config加密和安装脚本时存储在SQL Server连接字符串?

Any ideas how I can edit the web.config to encrypt and store the SQL Server connection string during the installation script?

更新#1 看起来既DpapiProtectedConfigurationProvider和RsaProtectedConfigurationProvider需要将FullTrust。是否有任何其他的解决方案使用MediumTrust时,以进一步保护Web.config文件?

Update #1 It seems both DpapiProtectedConfigurationProvider and RsaProtectedConfigurationProvider require FullTrust. Are there any other solutions to protect the Web.config file further when using MediumTrust?

推荐答案

如果您的供应商允许的话,你可以设置为在的如何:使用中等信任在ASP.NET 2.0中。但它是不可能的,他们会放过你。

If your provider allows it, you could setup a custom policy file as described in How To: Use Medium Trust in ASP.NET 2.0. But it is unlikely that they will let you.

您也可以尝试使用的XDocument / 的XmlDocument 的XPath 来获取/设置配置值,但你仍然有通过使用在中等信任运行库来处理加密/解密。 (编程修改配置部分中等信任

You could also try to use XDocument / XmlDocument and XPath to get/set config values, though you will still have to deal with the encryption/decryption by using a library that runs in medium trust. (see Modify configuration section programmatically in medium trust)

如果可能的话,你也可以尝试使用独立的进程,修改文件别的地方,然后让修改后的文件通过外部手段来上传到服务器,如FTP或IIS7的Web部署功能。

If possibly, you could also try to use a separate process that modifies the file somewhere else, and then allows the modified file to be upload to the server via external means, like FTP or the Web Deploy feature of IIS7.

这篇关于加密和使用中等信任在web.config中保存ASP.NET的ConnectionString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆