配置信息的存放位置:
在Asp.net中自定义配置信息可以有两种存放方式:1、存放在web.config中。2、存放在自定义的Xml文件中。
一、存放在Web.Config中。
又分为两种情况:1、存放在<appSettings></appSettings>配置节,2、存放在<configSections></configSections>配置节。
1、<appSettings>(AspnetForums没有使用该配置)。
使用:很简单,即一个个的“键值对”。
<add key="键" value="值" />读取:
System.Configuration.ConfigurationSettings.AppSettings["键"] 2、<configSections>(AspnetForums使用了该配置方法)。
使用:
<configSections>
<!-- Initialize the AspNetForums Configuration Handler -->
<sectionGroup name="forums">
<section name="forums" type="AspNetForums.Configuration.ForumsConfigurationHandler, AspNetForums.Components" />
</sectionGroup>
</configSections>读取:
System.Configuration.ConfigurationSettings.GetConfig()知识点:在.NET中,配置文件中所有的配置信息都要“经”IConfigurationSectionHandler 接口读出。
1、当使用<appSetting>读取配置时,Asp.Net自己实现了该接口,无需我们实现,使用即可。
2、当使用<congfigSections>读取配置时,需要我们自己实现该接口。
该接口很简单,只有一个方法:
object Create(Object parent, Object context, XmlNode node)
二、存放在自定义的Xml文件中。(例:AspnetForums的“SiteUrls.config”文件)
浙公网安备 33010602011771号