web.config文件中自定义配置节点
web.config中常用的节点有
这些节点能够解决我们遇到的大部分情况,但也有小部分情况下是不适用或者说不方便使用的。
web.config文件中声明自定义节点,内容如下:
<configuration> <configSections> <section name="mySettings" type="System.Configuration.NameValueFileSectionHandler, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> configSections> <mySettings> <add key="myKey" value="myValue"/> mySettings> configuration>
代码中的使用:
var mySettings = System.Configuration.ConfigurationManager.GetSection("mySettings") as NameValueCollection; string myValue= pushSettings["myKey"];
以上只是自定义配置节点的一种使用方式,自定义节点非常灵活有兴趣可以参考这篇文章:https://www.jb51.net/article/45689.htm