Re: Custom section in web.config

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi Juan,

I have a code for .NET Framework versions 1.0 and 1.1 and I already have
read this topic, but they have also written a note in this topic.

In the .NET Framework versions 1.0 and 1.1, a configuration section handler
had to implement the System.Configuration.IConfigurationSectionHandler
interface, which is now deprecated. However, a code example exists in How to:
Create Custom Configuration Sections Using IConfigurationSectionHandler.

I want a real .NET Framework version 2.0 code. Have you any example for
that? Thanks in advanced.

Aftab Ahmad
"Juan T. Llibre" wrote:

> This used to be real easy in 1.1 :
>
> <configuration>
> <configSections>
> <sectionGroup name="system.web">
> <section name="customSection"
> type="System.Configuration.NameValueSectionHandler,
> System, Version=1.0.5000.0, Culture=neutral,
> PublicKeyToken=b77a5c561934e089"/>
> </configSections>
> <customSection>
> <add key="customSection Key 1" value="Value for customSection Key 1"/>
> <add key="customSection Key 2" value="Value for customSection Key 2"/>
> </customSection>
> </configuration>
>
> See if :
> http://msdn2.microsoft.com/en-us/library/ms228062.aspx
> sheds any more light on this for ASP.NET 2.0.
>
>
>
> Juan T. Llibre, ASP.NET MVP
> ASP.NET FAQ : http://asp.net.do/faq/
> ASPNETFAQ.COM : http://www.aspnetfaq.com/
> Foros de ASP.NET en Español : http://asp.net.do/foros/
> ======================================
> <Tabi@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:53A0A894-0B02-463B-A165-D6694A3B54C8@xxxxxxxxxxxxxxxx
> > Hi,
> >
> > I want to create a custom section in my web.config that can hold my custom
> > values. I created a section in web.config as written below.
> >
> > <configSections>
> > <section name="myCustomSection"
> > type="ComIT.Applications.Common.ConfigurationSections.MyHandler"
> > allowLocation="true" allowDefinition="Everywhere" />
> > </configSections>
> >
> > <myCustomSection>
> > <add key="LastErrorKey1" value="LastError" />
> > <add key="LastErrorKey2" value="LastError" />
> > <add key="LastErrorKey3" value="LastError" />
> > <add key="LastErrorKey4" value="LastError" />
> > ...
> > </myCustomSection>
> >
> > Here is my MyHandler class
> >
> > namespace ComIT.Applications.Common.ConfigurationSections
> > {
> > public class MyHandler : ConfigurationSection
> > {
> > public MyHandler()
> > {
> > }
> > }
> > }
> >
> > I use this code to get my section.
> > MyHandler config =
> > (MyHandler)System.Configuration.ConfigurationManager.GetSection("myCustomSection");
> >
> > This gives me following error:
> > Unrecognized element 'add'. (c:\\Inetpub\\wwwroot\\MedTime\\web.config line
> > 21).
> >
> > I searched from msdn. I found this topic
> > http://msdn2.microsoft.com/en-us/library/2tw134k3.aspx. This does not fulfill
> > my requirement either.
> >
> > I need a simple section like built-in <appSettings> og <connectionStrings>
> > section. How can I do this?
> >
> > Cann't I define a property to my class MyHandler as
> > System.Collections.Specialized.NameValueCollection that can hold all the
> > values under my section like ConfigurationManager.AppSettings.
> >
> >
> > Aftab Ahmad
> > aa@xxxxxxxxx
>
>
>
>
>
>
.



Relevant Pages

  • Re: Custom section in web.config
    ... sheds any more light on this for ASP.NET 2.0. ... > I want to create a custom section in my web.config that can hold my custom ... > public class MyHandler: ConfigurationSection ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: IIS 6.0,ASP.NET 1.1 and confiig error
    ... "On" Always display custom messages. ... on the local Web server. ... This section sets the authentication policies of the application. ... configuration file located in the root directory of the current web ...
    (microsoft.public.windows.server.general)
  • Re: Windows Forms Stylesheets?
    ... if your users don't know how to modify Windows appearance I don't see how it would be any easier to teach them to use a custom ... As for role-based changes to the UI, I agree that file-based configuration could be useful to an extent, but you'll still have to ... You could also use the .NET 2.0 Providers framework to create configurable settings for certain aspects of the program. ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: urlMappings interaction with web.config hierarchy
    ... Presumably I either need a way to manually load configuration files before the Rewrite happens, or I need a way to execute a .aspx class as if it were located at a different location. ... I have written custom url mapping modules, but nothing I know how to do will allow me to solve my problem. ... that's not the currently execution directory, use the GetSection(string, ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Incorrect Server Error in config file
    ... I assumed that by publishing the site from vs2005 ... server I can browse to testpage.htm, ... custom errors in the config file. ... "web.config" configuration file located in the root directory of the ...
    (microsoft.public.dotnet.framework.aspnet)