1).配置文件格式
文件名为config.web,应用当前应用及其自目录下的应用。
WinNT\ComPlus\<version>\Config.web是整个系统的缺省配置。config.web不可能被浏览器访问到,即便放在WEB应用的目录下。
配置文件中分成两小节,第一节指出谁来处理配置信息,第二小节是具体的配置数据。
标准的ASP 配置处理器有:
<httpmodules> 处理所有的请求
<httphandlers> 将特定的URL映射到特定的处理器,子目录中应用不继承该配置。参考前面的http处理器和工厂。
<sessionstate> session状态处理器
<globalization>
<compilation> 编译相关的处理
<trace> asp Trace服务
<security> ASP 安全模块
<iisprocessmodel> iis处理模块
<browsercaps> 处理浏览器兼容信息的设置
2).获取配置信息
可以用API直接访问配置信息,比如Request.Browser对象的属性直接获得browsercapabilities
或者调用Context.GetConfig,比如:
CustomConfigSettings Config=(CustomConfigSettings)Context.GetConfig("customconfig");
if(config.Enabled==true)
......
GetConfig可有第二个参数获得指定的URL的配置。
下面是一个保存应用自己的配置数据的例:
<configuration>
<configsections>
<add name="databases" type="System.Web.Configuration.DictionarySectionHandler" />
</configsections>
<databases>
<add key="pubs" value="server=localhost;uid=sa;pws="/>
<add key="nothwind" value="server=localhost;uid=sa"/>
</databases>
</configuration>
使用:
String dsn = (String)((Hashtable)Context.GetConfig("databases"))["pubs"];
String strConnString;
Hashtable appSetting = new Hashtable();
appSetting = (Hashtable)(Context.GetConfig("appSettings"));
strConnString = appSetting["sqlConnectionString"].ToString();
String strConnect = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];