/// <summary>
/// web.config加密
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button1_Click(object sender, EventArgs e)
{
Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
//在打开的配置文件中找到指定的节
ConfigurationSection section = config.GetSection("appSettings");
if (section != null && !section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
config.Save();
Response.Write("<script>alert('加密成功!');</script>");
}
}
/// <summary>
/// web.config解密
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Button2_Click(object sender, EventArgs e)
{
Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
ConfigurationSection section = config.GetSection("appSettings");
if (section != null && section.SectionInformation.IsProtected)
{
section.SectionInformation.UnprotectSection();
config.Save();
Response.Write("<script>alert('解密成功');</script>");
}
}
web.config加密与解密
最新推荐文章于 2024-07-02 16:16:11 发布