G
Guest
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
(e-mail address removed)
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
(e-mail address removed)