Wednesday, April 9, 2008

How To Create User Defined Tag In WebConfig

WebConfig
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="YourTagName" type="System.Configuration.NameValueFileSectionHandler,System, Version=1.0.3300.0, Culture=neutral,PublicKeyToken=b77a5c561934e089"/>
.
.
.
.
</configSections>
<appSettings>
.
.
.
</appSettings>
<YourTagName>
<add key="YourKeyName1" value="Xploredotnet"/>
<add key="YourKeyName2" value="adminpwd"/>
</YourTagName>

.
.
.
.
.
</configuration>



Code Behind
This is one of the way to access Custom Tag

string AdUrs,AdPwd;
AdUrs = ((System.Collections.Specialized.NameValueCollection)ConfigurationManager.GetSection("YourTagName"))["YourKeyName1"] +string.Empty;
AdPwd = ((System.Collections.Specialized.NameValueCollection)ConfigurationManager.GetSection("YourTagName"))["YourKeyName2"] + string.Empty;

No comments: