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:

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...