<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="[email protected] /> </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="developer\developerappsetingstring.xml"/> <connectionStrings configSource="developer\developerconnectionstring.xml" /> <system.web> <membership configSource="developer\developermembership.xml"/> <compilation debug="true"/> <authentication mode="Forms"/> <authorization> <deny users="?"/> </authorization> </system.web> </configuration>
可以看到,在web.config中,可以通过configsource属性来读取外部文件