在asp.net 2.0中的web.config文件中调用外部文件
点击次数:26 次 发布日期:2008-11-26 12:42:20 作者:源代码网
|
源代码网推荐 使到我们可以先预先搞好几个文件,比如将经常要改动的部分,如数据库连接串部分等,按不同的开发环境,分别写成若干个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)。 源代码网推荐 源代码网供稿. |
