无法读取Web.Config中的appSettings值 [英] Can't read appSettings value from Web.Config

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

问题描述

我在我的web.config以下内容:

I have the following in my web.config:

<configuration>
    <appSettings>
        <add key="PsychMon" value="true"/>
    </appSettings>
 . . .
</configuration>



我在我的代码隐藏下面的代码:

I have the following code in my codebehind:

  System.Configuration.Configuration webConfig = 
System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(null) ; 



然而,当我看着webConfig,webConfig.AppSettings.Settings.Count = 0。

However, when I look at webConfig, webConfig.AppSettings.Settings.Count = 0 .

为什么不读应用程序设置?

Why is it not reading the app setting?

我想要做的是能拿到通过设置:

What I want to do is be able to get the setting by using:

          System.Configuration.KeyValueConfigurationElement psych = 
webConfig.AppSettings.Settings["PsychMon"];



我使用C#3.5,VS 2008

I am using c# 3.5, vs 2008

推荐答案

你为什么不只是写这个?

Why don't you just write this ?

string value = 
    System.Web.Configuration.WebConfigurationManager.AppSettings["PsychMon"];

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

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