【问题标题】:Encryption ConnectionStrings App.config加密连接字符串 App.config
【发布时间】:2016-02-10 22:39:22
【问题描述】:

我尝试使用下面的代码进行加密,但它只能在我的电脑上使用,其他电脑无法连接到我电脑中的 SQL 服务器。有人帮我吗?非常感谢!!! (我也尝试使用 aspnet_regiis.exe 但有同样的问题)

        public static void ProtectSection(String sSectionName)
    {
        Configuration config = ConfigurationManager.OpenExeConfiguration("TFLManager.exe");

        // Get the section in the file.
        ConnectionStringsSection section = config.GetSection(sSectionName) as ConnectionStringsSection;
        // If the section exists and the section is not readonly, then protect the section.
        if (section != null)
        {
            if (!section.IsReadOnly())
            {
                // Protect the section.
                section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
                section.SectionInformation.ForceSave = true;
                // Save the change.
                config.Save(ConfigurationSaveMode.Modified);
            }
        }
    }

【问题讨论】:

  • 您能否更具体地说明您在寻找什么?您想加密 Web.config 文件。
  • 我想加密app.config,我用aspnet_regiis.exe加密后,只有我的PC可以连接到SQL server(在我的PC上),其他PC无法连接。

标签: c# encryption app-config aspnet-regiis.exe


【解决方案1】:

在您想要的计算机上以管理员身份启动命令提示符。 在命令提示符下,输入:

 cd C:\Windows\Microsoft.NET\Framework\v4.0.30319

如果您的 Web Config 位于“D:\Code\EncryptWebConfig”目录路径中,则输入以下内容以加密 ConnectionString:

ASPNET_REGIIS -pef "connectionStrings" "D:\Code\EncryptWebConfig"

【讨论】:

    猜你喜欢
    • 2012-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-06
    • 2013-02-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多