Add Custom Configuration Sections In Web.Config (Asp.Net 2.0)

The Configuration Sections that are in Web.Config are basically classes defined in the .Net Framework and we just set the properties for site compilation and other necessary functionalities for site startup.

Custom Configuration Section
There are a few steps to make your Custom configuration section and configurable class in Asp.Net. Like i am writing a class which needs some custom file path to save temporary data.

// Inherit your Class from ConfigurationSection
public class SaveEmployeeData : ConfigurationSection
{
// In the below Line i ma telling .Net to look for
// an attribute Web.config file 'TempFolderPath' to retrive value.
[ConfigurationProperty("TempFolderPath", IsRequired = true)]
public string LogFilePath
{
get
{
return (string)base["TempFolderPath"];
}
set
{
base["TempFolderPath"] = value;
}
}
}


Now in the Web.Config file we will add some configurations

<configuration>
<configSections>
<section name="TempFolder" type="mynamespace.SaveEmployeeData"/>
</configSections>
<TempFolder TempFolderPath="/TempFolder"/>
</configuration>


Refrence = http://www.singingeels.com

Comments

Popular posts from this blog

Use configSource attribute to manage Web.Config sections in ASP.Net 2.0

DevOps - Key Concepts - Roles & Responsibilities - Tools & Technologies

Trouble In the House of Google