加密 Web.Config 中的连接字符串失败
我想加密我的 web.config 的连接字符串。 在这里我找到了一个关于如何执行此操作的很好的示例。我实现了这个并在我的开发机器上运行 find 。 但是,如果我将其上传到提供程序,则它不起作用并出现以下错误:
[SecurityException:请求失败。] System.Configuration.DpapiProtectedConfigurationProvider.Encrypt(XmlNode节点)
System.InvalidOperationException:此操作在运行时不适用
任何人都可以引导我吗?对于解决方案,我如何编码(和解码)web.config 文件中的连接字符串(在运行时)?
更新
这不是问题的真正答案,但托管商完全信任网络,现在一切正常。我将问题悬而未决,也许有人发布了原始问题的解决方案,并帮助有同样问题但没有得到充分信任的人。
I would like to encrypt the connection string of my web.config. Here I have found a nice example on how to do this. I implemented this and on my development machine this runs find.
However if I upload it to the provider, it does not work with the following error:
[SecurityException: Request failed.]
System.Configuration.DpapiProtectedConfigurationProvider.Encrypt(XmlNode node)
In this blog I have read, that this is because of the web probably runs in medium trust and therefore WebConfigurationManager.OpenWebConfiguration
can not be used. Instead of this, WebConfigurationManager.GetSection
should be used. However, if I get the section as proposed, the call to ProtectSection
fails with the following error message:
System.InvalidOperationException: This operation does not apply at runtime
Can anyone lead me to a solution, how I can encode (and decode) the connection string in the web.config file (at runtime)?
Update
Not a real answer to the question, but the hoster gave full trust to the web and now, all worked fine. I leave the quesion open, maybe someone posts a solution to the original question and helps with this people having the same problem but not getting full trust.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 http://msdn.microsoft.com/ en-us/library/89211k9b%28v=vs.80%29.aspx
更新
另外,请确保您的服务帐户具有 Web.config 的写入权限。另外,请注意,向 Web.config 上的服务帐户授予写入权限会在一定程度上增加应用程序的安全足迹。仅当您了解并接受风险时才这样做。
From http://msdn.microsoft.com/en-us/library/89211k9b%28v=vs.80%29.aspx
UPDATE
Also, ensure that your service account has write permissions to the Web.config. Also, be aware that granting write permissions to your service account on the Web.config increases somewhat the security footprint of your application. Only do so if you understand and accept the risks.