473,394 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Custom section in web.config

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.ConfigurationSecti ons.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.ConfigurationManag er.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@com-it.dk

Nov 20 '05 #1
6 3777
Hi Tabi,

Use System.Configuration.NameValueSectionHandler, it exactly does what you
want

rgrds
--
Bindesh Vijayan
MCP [ASP.NET]
"Tabi" wrote:
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.ConfigurationSecti ons.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.ConfigurationManag er.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@com-it.dk

Nov 20 '05 #2
Hi binvij,

Have you any example for that?

Tabi

"binvij" wrote:
Hi Tabi,

Use System.Configuration.NameValueSectionHandler, it exactly does what you
want

rgrds
--
Bindesh Vijayan
MCP [ASP.NET]
"Tabi" wrote:
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.ConfigurationSecti ons.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.ConfigurationManag er.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@com-it.dk

Nov 20 '05 #3
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 Espaol : http://asp.net.do/foros/
======================================
<Ta**@discussions.microsoft.com> wrote in message
news:53**********************************@microsof t.com...
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.ConfigurationSecti ons.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.ConfigurationManag er.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@com-it.dk


Nov 20 '05 #4
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/
======================================
<Ta**@discussions.microsoft.com> wrote in message
news:53**********************************@microsof t.com...
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.ConfigurationSecti ons.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.ConfigurationManag er.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@com-it.dk



Nov 20 '05 #5
Maybe I'm reading that page wrong, but just because it says that
"a configuration section handler had to implement the
System.Configuration.IConfigurationSectionHandler interface,
which is now deprecated" doesn't mean that page shows how to use
the System.Configuration.IConfigurationSectionHandler interface.

In fact, it doesn't.

The sample for 1.0/1.1 is at :
http://msdn2.microsoft.com/en-us/library/ms228056.aspx
and is a totally different coding method than what
http://msdn2.microsoft.com/en-us/library/ms228062.aspx
and the links on that page demonstrate.

See, in :
http://msdn2.microsoft.com/en-us/library/2tw134k3.aspx
the sections titled :

"To create a custom configuration section handler"
"To add a custom section handler to an ASP.NET configuration file"
"To programmatically access your custom configuration data"

Those do *not* use "IConfigurationSectionHandler"; they use
"System.Configuration.ConfigurationSection", a 2.0 class.

See this reference:
http://msdn2.microsoft.com/en-us/lib...onsection.aspx

There's example code on that page.


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 Espaol : http://asp.net.do/foros/
======================================
"Tabi" <Ta**@discussions.microsoft.com> wrote in message
news:AC**********************************@microsof t.com...
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 Espaol : http://asp.net.do/foros/
======================================
<Ta**@discussions.microsoft.com> wrote in message
news:53**********************************@microsof t.com...
> 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.ConfigurationSecti ons.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.ConfigurationManag er.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@com-it.dk




Nov 20 '05 #6
Hi Juan,

Thanks for your answer. I have already read all these links. I am trying to
find this out for last three days.

If you read my first email. I am using ConfigurationSection class but this
class supports only node without child nodes in the web.config. That means
that you can not populate children to this node. If you try to add “add” node
then you get following error.

"Unrecognized element 'add'. (c:\\Inetpub\\wwwroot\\MedTime\\web.config line
21.)"

When I use IConfigurationSectionHandler with
ConfigurationSettings.GetConfig() method then although it works but at the
same time it gives warning that “This method is obsolete. This method has
been replaced by ConfigurationManager.GetSection”.

Why have they made it so difficult? It was so easy in .NET 1.1. As I have
written before that I have also read this topic
http://msdn2.microsoft.com/en-us/library/2tw134k3.aspx where you can add
section group and populate also section child nodes but this is not good
solution. It works fine if you have only one section and child nodes but if
you have 100 sections of different types then your have create 100 classes to
read every section. Is it correct?

Is there any better solution in .NET 2.0? Thanks in advanced.

Aftab
"Juan T. Llibre" wrote:
Maybe I'm reading that page wrong, but just because it says that
"a configuration section handler had to implement the
System.Configuration.IConfigurationSectionHandler interface,
which is now deprecated" doesn't mean that page shows how to use
the System.Configuration.IConfigurationSectionHandler interface.

In fact, it doesn't.

The sample for 1.0/1.1 is at :
http://msdn2.microsoft.com/en-us/library/ms228056.aspx
and is a totally different coding method than what
http://msdn2.microsoft.com/en-us/library/ms228062.aspx
and the links on that page demonstrate.

See, in :
http://msdn2.microsoft.com/en-us/library/2tw134k3.aspx
the sections titled :

"To create a custom configuration section handler"
"To add a custom section handler to an ASP.NET configuration file"
"To programmatically access your custom configuration data"

Those do *not* use "IConfigurationSectionHandler"; they use
"System.Configuration.ConfigurationSection", a 2.0 class.

See this reference:
http://msdn2.microsoft.com/en-us/lib...onsection.aspx

There's example code on that page.


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" <Ta**@discussions.microsoft.com> wrote in message
news:AC**********************************@microsof t.com...
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/
======================================
<Ta**@discussions.microsoft.com> wrote in message
news:53**********************************@microsof t.com...
> 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.ConfigurationSecti ons.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.ConfigurationManag er.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@com-it.dk



Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Sren Lund | last post by:
Hello, I have implemented a custom config section handler by implementing the IConfigurationSectionHandler interface. I have registered this handler in web.config and everything works fine ......
4
by: Nick Gilbert | last post by:
Hi, I would like the ability to store the configuration settings for all versions of my site in a single web.config file by using different sections. Eg: <siteConfig> <machine name="XENON">...
0
by: Giorgio | last post by:
It seems that the ASP.NET Microsoft team didn't think about this!! The profilemanager class has the following methods: - DeleteInactiveProfiles. Enables you to delete all profiles older...
1
by: npaulus | last post by:
Hi I am trying to experiment with a custom configuration section in app.config but it just doesnt work. app.config: <?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections>...
2
by: Laurent Bugnion | last post by:
Hi, I like to develop custom controls for a number of webpages. These controls are often customizable, so that they can be reused in a number of situations. My question is: What is the best...
6
by: Jeff Hegedus | last post by:
I have a dll that requires some configuration data. I put the configuration data in a custom configuration section in a config file that is loaded in the installation folder of the dll. If I...
7
by: =?Utf-8?B?RG91Z2llIEJyb3du?= | last post by:
Hi I've written custom configuration section (inherits from System.Configuration.ConfigurationSection) to simplify the contents of the config file and to make life easier when accessing them in...
2
by: Smithers | last post by:
I have a Windows Forms application that implements a plug-in architecture whereby required assemblies are identified and loaded dynamically. Here are the relevant classes: A = application =...
0
by: =?Utf-8?B?UGhpbGlw?= | last post by:
I have a web.config custom configuration section using asp.net 2.0 configuration APIs. My custom configuration section inherits from System.Configuration.ConfigurationSection. I have a IIS root...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.