加密Web.Config配置文件

protected void btnPassWord_Click(object sender, EventArgs e)
    {
         //加密
        Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
        ConfigurationSection section = config.GetSection("appSetting");
        if (section != null && !section.SectionInformation.IsProtected)
        {
            section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
            config.Save();
            Response.Write("<script>alert('加密成功');</script>");
        }


需要解密文件配置的时候,只需调用SectionInformation类的UnprotectSection方法。

posted @ 2013-09-04 16:25  秋水惜朝  阅读(335)  评论(0编辑  收藏  举报