首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >不使用命令行工具加密web.config

不使用命令行工具加密web.config
EN

Stack Overflow用户
提问于 2012-07-25 01:55:29
回答 1查看 708关注 0票数 0

我想加密位于我的web.config文件中的appSettingsConnectionStrings

但由于我使用的是共享主机,所以不能使用aspnet_regiis.exe方法。

有没有其他的方法来加密web.config文件?(在线工具、远程工具、编程方式或...)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-25 02:09:20

没有由我测试,从CodeProject,希望它将工作Aspx代码:

代码语言:javascript
运行
复制
 <asp:Button id="btnEncrypt" runat="server" Text="Encrypt" onclick="btnEncrypt_Click" />
 <asp:Button ID="btnDecrypt" runat="server" Text="Decrypt" onclick="btnDecrypt_Click" />

 Code Behind:

    string provider = "RSAProtectedConfigurationProvider";
    string section = "connectionStrings";
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btnEncrypt_Click(object sender, EventArgs e)
    {
       Configuration confg = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
       ConfigurationSection configSect = confg.GetSection(section);
       if (configSect != null)
       {
          configSect.SectionInformation.ProtectSection(provider);
          confg.Save();
       }
    }

    protected void btnDecrypt_Click(object sender, EventArgs e)
    {
       Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
       ConfigurationSection configSect = config.GetSection(section);
       if (configSect.SectionInformation.IsProtected)
       {
          configSect.SectionInformation.UnprotectSection();
          config.Save();
       }
    }

http://www.codeproject.com/Tips/304638/Encrypt-or-Decrypt-Connection-Strings-in-web-confi

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11636578

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档