using System.Configuration;
using System.Web.Configuration;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Configuration config = WebConfigurationManager.OpenWebConfiguration("~/");//获取web.config配置信息
ConfigurationSection appSettings = config.GetSection("appSettings");//获取appsettings配置信息
if (appSettings.SectionInformation.IsProtected)//判断是否加密,是就解密,不是就加密
{
appSettings.SectionInformation.UnprotectSection();
}
else
{
appSettings.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
}
config.Save();
}