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();
}
本文介绍了一个使用 ASP.NET 对 web.config 中的 appSettings 部分进行加密和解密的示例代码。通过判断 appSettings 是否已加密来决定执行解密还是加密操作。

959

被折叠的 条评论
为什么被折叠?



