如何读取在Web.config文件中的appSettings节? [英] How to read appSettings section in the web.config file?

查看:214
本文介绍了如何读取在Web.config文件中的appSettings节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的XML看起来是这样的。和名称为的web.config

My xml looks like this. and the name is web.config

<?xml version="1.0"?>
<configuration>
  <appSettings>   
    <add key="configFile" value="IIS.config"/>
    <add key="RialtoDomain" value="ASNC_AUDITORS"/>    
  </appSettings>
  <system.serviceModel>
    ....
  </system.serviceModel>
</configuration>

在code,当我读到这样的

In the code when I read like this

String path = ConfigurationSettings.AppSettings["configFile"];

在这里,我得到一个空值。这里也不例外抛出。 这是正确的做法?或者有没有其他的方法?

Here I am getting a null value. No exception thrown here. Is this right way to do? or is there any other method?

在此先感谢。 等待答复。

Thanks in advance. Waiting for the response.

推荐答案

既然你访问一个的web.config 你应该使用

Since you're accessing a web.config you should probably use

using System.Web.Configuration;

WebConfigurationManager.AppSettings["configFile"]

这篇关于如何读取在Web.config文件中的appSettings节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆