Protected Sub btnEncrypt_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnEncrypt.Click Dim config As System.Configuration.Configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath) Dim section As ConfigurationSection = config.GetSection("connectionStrings") If section IsNot Nothing AndAlso Not section.SectionInformation.IsProtected Then section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider") config.Save() End If End Sub Protected Sub btnDecrypt_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnDecrypt.Click Dim config As System.Configuration.Configuration = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath) Dim section As ConfigurationSection = config.GetSection("connectionStrings") If section IsNot Nothing AndAlso section.SectionInformation.IsProtected Then section.SectionInformation.UnprotectSection() config.Save() End If End Sub
代码加密解密web.config
最新推荐文章于 2023-08-07 16:54:19 发布
本文介绍了一个使用ASP.NET的Web应用程序中如何通过按钮点击事件来加密或解密配置文件中的connectionStrings节。提供了具体的VB.NET代码实现,展示了如何在运行时动态地保护或解除保护配置信息。
866

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



