定义在web.config中的<appSettings>元素中的键值可被所有子文件夹中的aspz文件使用.方便修改多个aspx文件的数据.

以数据库连接为例:
1,
web.config中
...
</system.web>
<appSettings>
<add key = "Nwind"
 value = "server=(local)\NetSdk;database=Northwind;integrated security=true;"/>
</appSettings>
</configuration>

在aspx文件中引用它:
string strConn = ConfigurationSettings.AppSettings["Nwind"];

2,
可以通过以下方法来获取数据库在远程主机的真实目录物理路径。假定,在上传远程空间的域名地址如下:

http://www.pconline.com.cn/dkblog

3,
使用asp.net编程会使用到Server.MapPath相对路径.
暂时想到一个简单的解决办法:
web.config中
 <appSettings>
  <add key = "accPath" value = "provider = microsoft.Jet.OLEDB.4.0;Data Source=" />
  <add key = "accName" value = "account.mdb" />
  </appSettings>

aspx中
 string strPath = ConfigurationSettings.AppSettings["accPath"];
 string strName = ConfigurationSettings.AppSettings["accName"];
 string strConn = strPath + Server.MapPath(strName);

posted on 2006-07-26 13:51  新世代三无人  阅读(1795)  评论(0编辑  收藏  举报