保护 Windows Azure 和 web.config 中的连接字符串

发布于 2024-10-05 13:03:49 字数 919 浏览 0 评论 0原文

我对 web.config 中的连接字符串进行加密,如下所述:
http://blogs.msdn.com/b/sqlazure /archive/2010/09/07/10058942.aspx
发布到 Azure,一切都按预期运行。

但现在我面临着本地开发的问题,我在本地数据库上工作,不需要连接字符串的加密。
我的本地开发配置为调试配置,我尝试替换(转换)web.config 的加密连接字符串部分,例如:

<connectionStrings configProtectionProvider="CustomProvider">
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
 ...
</EncryptedData>

将常规非加密部分添加到 web.config.debug 时,

<connectionStrings>
<add name="ApplicationServices" connectionString="data source=localhost...
</connectionStrings>

我可以毫无问题地使用 xdt:Transform="Insert 添加这些部分,但我无法从 web.config 中删除这些部分。
它会导致解析器错误消息:在调试模式下执行 Web 项目时无法识别元素“EncryptedData”。

有没有办法删除 web.config.debug 的 EncryptedData 部分,或者有更好的做法来克服此问题?

I encrypt the connection string in web.config like described here:
http://blogs.msdn.com/b/sqlazure/archive/2010/09/07/10058942.aspx
published to Azure and everything is working as expected.

BUT now I am facing a problem for my local development where I work against a local database where I don't need encryption of the connection string.
My local development is configured as debug configuration and I tried to replace (transform) the encrypted connectionstrings section of web.config like:

<connectionStrings configProtectionProvider="CustomProvider">
<EncryptedData Type="http://www.w3.org/2001/04/xmlenc#Element"
 ...
</EncryptedData>

with the regular non encrypted section to web.config.debug

<connectionStrings>
<add name="ApplicationServices" connectionString="data source=localhost...
</connectionStrings>

I had no problem adding the sections with xdt:Transform="Insert, but I did not manage to delete the sections from web.config.
It results in an Parser Error Message: Unrecognized element 'EncryptedData' when executing the web project in debug mode.

Is there any way deleting the EncryptedData section for web.config.debug, or a better practice to overcome this problem ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一直在等你来 2024-10-12 13:03:49

只是想知道...为什么要保护连接字符串?您可以将连接字符串放入 .cscfg 文件中,并且该文件不会以任何方式通过 IIS 公开。

Just wondering... why do you want to secure the connection string? You can put the connection string in the .cscfg file, and that file is not exposed in any way through IIS.

揪着可爱 2024-10-12 13:03:49

是的,您可以将它们放入 .csfg 文件中并创建一个库来提取连接字符串(只需提供 DLL):

public class MyContext : DbContext
{
    private MyContext(string connString)
        : base(connString)
    {
    }

    public static MyContext GetMyContext()
    {
        string dbConnString = CloudConfigurationManager.GetSetting("MyDbConnectionString");

        return new MyContext(decrypt(dbConnString));
    }
}

Yes, you can put them in a .csfg file and make a library to extract the connectionstring (just supply the DLL):

public class MyContext : DbContext
{
    private MyContext(string connString)
        : base(connString)
    {
    }

    public static MyContext GetMyContext()
    {
        string dbConnString = CloudConfigurationManager.GetSetting("MyDbConnectionString");

        return new MyContext(decrypt(dbConnString));
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文