Re: Custom section in web.config
- From: "Tabi" <Tabi@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 18 Nov 2005 03:05:04 -0800
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
>
>
>
>
>
>
.
- Follow-Ups:
- Re: Custom section in web.config
- From: Juan T. Llibre
- Re: Custom section in web.config
- References:
- Re: Custom section in web.config
- From: Juan T. Llibre
- Re: Custom section in web.config
- Prev by Date: ASP.Net 2.0 menu control causing non-secure dialog
- Next by Date: Page redirect problem
- Previous by thread: Re: Custom section in web.config
- Next by thread: Re: Custom section in web.config
- Index(es):
Relevant Pages
|