1. MasterPage
Call Method
Private void GetConfig ()
{
NameValueCollection channelCollection = new CooperationChannelsConfig (). Settings;
Foreach (String channel in channelCollection)
{
If (channel. Equals (UIHelper. GetServerName (this. Page )))
{
DomainName = channelCollection [channel]. Split ('|') [0]. ToString ();
This. Page. Title = channelCollection [channel]. Split ('|') [1]. ToString ();
Break;
}
}
}
2. CooperationChannelsConfig:
// Implement a class that supports the IConfigurationSectionHandler interface to process custom sections and read them.
Namespace Config
{
Using System;
Using System. Data;
Using System. Configuration;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
Using System. Collections. Specialized;
Using System. Xml;
Public class CooperationChannelsConfig: IConfigurationSectionHandler
{
Public object Create (object parent, object configContext, XmlNode section)
{
NameValueCollection settings;
Try
{
NameValueSectionHandler baseHandler = new NameValueSectionHandler ();
Settings = (NameValueCollection) baseHandler. Create (parent, configContext, section );
}
Catch
{
Settings = null;
}
Return settings;
}
/** // <Summary>
/// Return the entire Channel
/// </Summary>
Public NameValueCollection Settings
{
Get
{
Return (NameValueCollection) ConfigurationManager. GetSection ("channel ");
}
}
}
}
3. Create a Global file in the project and add a sentence in the Application_Start () event to get the GetSection:
System. Configuration. ConfigurationManager. GetSection ("channel ");
4. Configure the mapping class and the custom config file used only in Web. config:
<Section name = "channel" type = "Config. CooperationChannelsConfig, Config"/>
<Channel configSource = "Config \ Channel. config"/>
5. Channel. config: Custom Config File
<? Xml version = "1.0" encoding = "gb2312"?>
<Channel>
<Add key = "Key" value = "value"/>
<Add key = "Key1" value = "value1"/>
</Channel>
Finally, I also provide an example of the custom configuration section above MSDN:
Ms-help: // MS. MSDNQTR. v80.chs/MS. MSDN. v80/MS. VisualStudio. v80.chs/dv_aspnetconfig/html/07f68a3f-2920-4665-a316-47bda744e662.htm