This Function for Protect the Configuration section
privatevoid UnProtectSection(string sectionName)
{
Configuration config =WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
ConfigurationSection section = config.GetSection(sectionName);
if (section.SectionInformation.IsProtected)
{
section.SectionInformation.UnprotectSection();
config.Save();
}
}
This Function for UnProtect the Configuration section
Please remember to click "Mark as Answer" on this post if it helped you
Why would you need to protect your web.config file? it is only accessible locally anyway is it not? and as i understand it cant be changed programatically?
It's only for a trick to protect our webconfig file, not a question.And why not is it not possible .it is possible to change the web config file programaticly.
Please remember to click "Mark as Answer" on this post if it helped you
Contributor
4954 Points
1726 Posts
Protect the Configuration File
Apr 02, 2008 10:31 AM|thirumaran007|LINK
Hi,
A sample Code for Protect Web.config file.
1.Create New Website
2.Add New Page
3.Place the Two Buttons and named as "ProtectConfig" and "UnProtectConfig"
4.In UnProtectConfig's Click Event write the following code
protected void ProtectConfig_Click(object sender, EventArgs e) { ProtectConfiguration("appSettings","DataProtectionConfigurationProvider"); }
Here the "appSettings" means we have to protect the webconfig's appSettings sections
and "DataProtectionConfigurationProvider" is the provider to Protect the Configuration file.
4.In ProtectConfig's Click Event write the following code
Here the "appSettings" means we have to UnProtect the section
4.And then add the Following User Defined Functin for Protect and Unprotect
This Function for UnProtect the Configuration section
With Friendly,
Thirumaran
All-Star
24872 Points
4336 Posts
ASPInsiders
Moderator
MVP
Re: Protect the Configuration File
Apr 02, 2008 10:59 AM|vcsjones|LINK
I'm sorry, but I don't understand or see a question. Are you asking a question, or are you providing the forums with a tip or trick?
Member
11 Points
12 Posts
Re: Protect the Configuration File
Apr 02, 2008 11:46 AM|ShaunRigby|LINK
Why would you need to protect your web.config file? it is only accessible locally anyway is it not? and as i understand it cant be changed programatically?
Contributor
4954 Points
1726 Posts
Re: Protect the Configuration File
Apr 03, 2008 12:26 AM|thirumaran007|LINK
Hi guys,
It's only for a trick to protect our webconfig file, not a question.And why not is it not possible .it is possible to change the web config file programaticly.
With Friendly,
Thirumaran