Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define Net4
- #if Net4
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Configuration;
- using System.Web.Configuration;
- using System.Web;
- namespace Core.Configuration {
- /// <summary>
- /// Protects/UnProtects Web.config file sections
- /// </summary>
- public class WebConfigProtection {
- HttpRequestBase Request { get; set; }
- public WebConfigProtection(HttpRequestBase req) {
- Request = req;
- }
- public void ProtectSection(string sectionName,string provider = "DataProtectionConfigurationProvider") {
- System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
- ConfigurationSection section = config.GetSection(sectionName);
- if(section != null && !section.SectionInformation.IsProtected) {
- section.SectionInformation.ProtectSection(provider);
- config.Save();
- }
- }
- public void UnProtectSection(string sectionName) {
- System.Configuration.Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
- ConfigurationSection section = config.GetSection(sectionName);
- if(section != null && section.SectionInformation.IsProtected) {
- section.SectionInformation.UnprotectSection();
- config.Save();
- }
- }
- }
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment