C#代码获取web.config中的配置信息

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011176794/article/details/52452040

1.在web.Config的<configuration>节点下面添加 <appSettings>节点

<configuration>

  <appSettings>

    <add key="Node1" value="Node1Value"/>
    <add key="Node2" value="Node2Value"/>
    <add key="Node3" value="Node3Value"/>

 </appSettings>

</configuration>

2.获取appSettings节点下面的子节点的信息

      

       public static string GetNode1Value()
        {
            return ConfigurationSettings.AppSettings["Node1"];
        }

       public static string GetNode2Value()
        {
            return ConfigurationSettings.AppSettings["Node2"];
        }

       public static string GetNode3Value()
        {
            return ConfigurationSettings.AppSettings["Node3"];
        }


展开阅读全文

没有更多推荐了,返回首页