无法读取Web配置文件值 [英] Unable to read web config file value

查看:64
本文介绍了无法读取Web配置文件值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网络配置中设置了一个值,我想在我的代码中读取它。但每当我运行它时,它返回argumentnullvalue异常。我之前已成功读取其他键的值,但这次失败了。

以下是我的代码:

Hi, I have a value set in web config and I want to read it in my codes. But whenever I run it, it returns argumentnullvalue exception. I have previously successfully read the value for other key but it failed this time.
Below are my codes:

<appSettings>
<add key="FlagWebAPI" value="true"/>
</appSettings>




public bool FlagWebAPI 
        {
            get 
            {
                bool flag;
                flag = Boolean.Parse(ConfigurationManager.AppSettings["FlagWebAPI"]);

                return flag;
            }
            set { }
        }





我尝试过:



1.尝试删除布尔解析并将数据类型转换为字符串但是获得相同错误消息。



What I have tried:

1. Tried to remove boolean parsing and and convert data type to string but getting the same error message.

推荐答案

那么你不会把设置放在web.config中的正确位置,或者你的设置还有其他的东西你我没有告诉我们。



Then you won't be putting the setting in the right place in the web.config, or there is something else about your set-up you're not telling us.

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <appSettings>
    <add key="FlagWebAPI" value="true"/>
  </appSettings>


这篇关于无法读取Web配置文件值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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