[英]Overwrite ConnectionString in web.config ASP.NET MVC
I'm trying to encrypt parts of my web.config file.(Passwords) This works fine for normal Section-Keys like that: 我正在尝试加密我的web.config文件的一部分。(密码)对于像这样的普通Section-Key来说,它可以正常工作:
<AppSettings>
<add key="SomePassword" value="HI I AM ENCRYPTET"/>
<AppSettings>
In the Global.asax i do the following: 在Global.asax中,执行以下操作:
System.Configuration.ConfigurationManager.AppSettings["SomePassword"] = Decrypt(System.Configuration.ConfigurationManager.AppSettings["SomePassword"])
This works fine. 这很好。 But when I try this for the Connection-String, an exception is thrown: "The configuration is read only."
但是,当我尝试对Connection-String进行此操作时,将引发异常:“配置为只读”。
So, I have no right to write. 因此,我无权写。 Does somebody know how to solve this without editing the Connection-String class?
有人知道如何在不编辑Connection-String类的情况下解决此问题吗?
Thanks & Greetings 谢谢和问候
You can move secrets out of your web.config file via: 您可以通过以下方式将机密移出web.config文件:
<appSettings file="..\..\AppSettingsSecrets.config">
See Best practices for deploying passwords and other sensitive data to ASP.NET and Azure Websites. 请参阅将密码和其他敏感数据部署到ASP.NET和Azure网站的最佳做法。 http://www.asp.net/identity/overview/features-api/best-practices-for-deploying-passwords-and-other-sensitive-data-to-aspnet-and-azure
http://www.asp.net/identity/overview/features-api/best-practices-for-deploying-passwords-and-other-sensitive-data-to-aspnet-and-azure
For Azure, I like to use http://www.powershellcookbook.com/recipe/PukO/securely-store-credentials-on-disk to encrypt credentials to disk. 对于Azure,我喜欢使用http://www.powershellcookbook.com/recipe/PukO/securely-store-credentials-on-disk在磁盘上加密凭据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.