当前位置:首页 > 网络编程 > WEB编程 > ASP.net >  在asp.net 2.0中的web.config文件中调用外部文件

 在asp.net 2.0中的web.config文件中调用外部文件

点击次数:26 次 发布日期:2008-11-26 12:42:20 作者:源代码网
源代码网推荐      在一个工作项目或者工作小组中,有可能经常要转换工作的调试环境,比如开发环境,测试环境,部署环境,这样有可能要对web.config文件进行修改或改动,比如要改数据库的连接字符串,角色配置,安全配置环境等,一不小心,很容易会发生遗漏等错误.在asp.net 2.0的web.config文件中,新加入了可以引入外部文件的新特性,
源代码网推荐  使到我们可以先预先搞好几个文件,比如将经常要改动的部分,如数据库连接串部分等,按不同的开发环境,分别写成若干个xml文件,然后在web.config中把它们按需要调入进来.比如
源代码网推荐  
源代码网推荐  我们先建立两个目录,一个叫test,一个叫developer,分别存放测试和开发时,用到的不同环境,比如
源代码网推荐  在devloper文件中建立一个developerconnectionstring.xml,内容如下
源代码网推荐  
源代码网推荐  <connectionStrings>
源代码网推荐  <add name="connstr" connectionString=
源代码网推荐  "data source=.sqlexpress;initial catalog=
源代码网推荐  northwind;integrated security=true"
源代码网推荐  providerName="System.Data.SqlClient"/>
源代码网推荐  </connectionStrings>
源代码网推荐  再建立一个developerappsetingstring.xml如下<appSettings>
源代码网推荐  <add key="autoemail" value="abc@abc.com /> </appSettings>
源代码网推荐  
源代码网推荐  
源代码网推荐  
源代码网推荐  再建立一个developermembership.xml如下
源代码网推荐  
源代码网推荐  <membership defaultProvider="Northwind">
源代码网推荐  <providers>
源代码网推荐  <add name="Northwind"
源代码网推荐  type="System.Web.Security.SqlMembershipProvider"
源代码网推荐  connectionStringName="connstr"/>
源代码网推荐  </providers>
源代码网推荐  </membership>
源代码网推荐  同样道理,可以在test目录下,也建立相关类似的xml文件,然后,在web.config中,可以这样调用了
源代码网推荐  <?xml version="1.0"?>
源代码网推荐  <configuration>
源代码网推荐  <appSettings configSource="developerdeveloperappsetingstring.xml"/>
源代码网推荐  <connectionStrings
源代码网推荐  configSource="developerdeveloperconnectionstring.xml" />
源代码网推荐  <system.web>
源代码网推荐  <membership
源代码网推荐  configSource="developerdevelopermembership.xml"/>
源代码网推荐  <compilation debug="true"/>
源代码网推荐  <authentication mode="Forms"/>
源代码网推荐  <authorization>
源代码网推荐  <deny users="?"/>
源代码网推荐  </authorization>
源代码网推荐  </system.web>
源代码网推荐  </configuration>
源代码网推荐   可以看到,在web.config中,可以通过configsource属性来读取外部文件
源代码网推荐  
源代码网推荐  jackyrong BLOG
源代码网推荐  
源代码网推荐  
源代码网推荐    做人要厚道,请注明转自酷网动力(www.ASPCOOL.COM)。
源代码网推荐


源代码网供稿.
网友评论 (0)
会员中心
网络编程
本站推荐
网络编程之精华