Groups > Asp .Net > ASP dotNET Security > Re: Protect the Configuration File




Re: Protect the Configuration File

Re: Protect the Configuration File
Wed, 2 Apr 2008 14:59:39 +0000
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?
Post Reply
Re: Protect the Configuration File
Wed, 2 Apr 2008 15:46:46 +0000
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?
Post Reply
Protect the Configuration File
Wed, 2 Apr 2008 17:31:08 +0000
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

protectedvoid ProtectConfig_Click(object sender, EventArgs e)
{
   
ProtectConfiguration("appSettings","DataProtectionConfigurationPr
ovider");
}

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

protectedvoid UnProtectConfig_Click(object sender, EventArgs e)
{
   UnProtectConfiguration("appSettings");
}


Here the "appSettings" means we have to UnProtect the section

4.And then add the Following User Defined Functin for Protect and Unprotect

privatevoid ProtectConfiguration(string sectionName,string provider)
{
    Configuration config =WebConfigurationManager.
OpenWebConfiguration(Request.ApplicationPath);

    ConfigurationSection section = config.GetSection(sectionName);

    if (!section.SectionInformation.IsProtected)
    {
        section.SectionInformation.ProtectSection(provider);
        config.Save();
    }
}

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
Post Reply
Re: Protect the Configuration File
Thu, 3 Apr 2008 04:26:15 +0000
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.
Post Reply
about | contact