在日常的网站建设中,经常会用到web.config,但如何使用web.config文件以及格式和注册呢?今天绵阳动力网络公司为大家介绍web.config使用方法,具体格式,注意点等方面,有需要的小伙伴可以参考下。
<connectionStrings configSource="db.config"/>
外部文件db.config:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;
Initial Catalog=aspnet-WebApplication1-20140304225906;
Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-WebApplication1-20140304225906.mdf"
providerName="System.Data.SqlClient" />
<add name="ReportServerTempDBConnectionString" connectionString="Data Source=.; Initial Catalog=ReportServerTempDB;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
具体格式
<节点名 configSource="配置文件路径"/>
注意点
1.如果指定了configSource,就以外部文件为准,web.config中connectionStrings下面的节点配置就无效了,即使web.config中connectionStrings下面的连接串节点没有删除掉也是无效的。
2.外部文件的根节点必须与web.config中指定的节点相同(其实就是将该节点的配置移到外部文件中)
3.一个节点只能指定一个外部配置文件,不能将多个节点的外部文件指定为同一个,如不能将connectionStrings与appSettings的configSource指定为同一个文件。
节点的数据获取
ConfigurationManager.GetSection("节点名");//返回的是一个节点对象
假想:架设以后ASP.NET5跨平台,使用json当做配置文件,应该也可以同样实现吧!