Tuesday, May 27, 2008

Adding new section to web.config - Microsoft ASP.NET

Create new section handeler for your new config section (implement IConfigurationSectionHandler interface)

Add a reference to your new config section and register it with the assembly

    public class CustomConfiguration : IConfigurationSectionHandler
    {
        public object Create(object parent, object input, XmlNode node)
        {
            /// 
            /// add your logic here ...
            /// 
            return new object();
        }
    }

Set custom configuration section in application start event(global.ascx) and add it to the cache

<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
  <configSections>
    <section name="customConfiguration" 
             type="Root.Client.Configuration.CustomConfiguration, Root.Client.Configuration" />
  </configSections>
  <customConfiguration>
    .....
    //
    // your custom configuration
    //
    .....
    <customConfiguration>
</configuration>
public override void Application_Start(object sender, EventArgs e)
{
    HttpContext.Current.Cache.Insert("CustomConfiguration", 
        ConfigurationSettings.GetConfig("customConfiguration"as CustomConfiguration);
}

No comments:

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...