无法从web.config中读取值 [英] Failing to read value from web.config

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

问题描述



我正在使用推荐的方法从web.config文件中读取值(我认为).使用Visual Studio内置的Web服务器时,此方法工作正常,但如果使用本地IIS服务器,则失败.这是我正在使用的代码:

Hi,

I am using the recommended way to read values from the web.config file (I think). This works fine when using the web server built into Visual Studio but fails if I use the local IIS server. This is the code I am using:

public class Global : System.Web.HttpApplication
{
    protected void Application_Start( object sender, EventArgs e )
    {
        KeyValueConfigurationElement settingKeyValuePair;
        System.Configuration.Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration( "/" );
        settingKeyValuePair = rootWebConfig.AppSettings.Settings[ "DomainForEmails" ];
        var v = settingKeyValuePair.Value;
}



变量 rootWebConfig 返回为NULL.我不知道为什么.任何帮助或建议,将不胜感激.

帕特里克



The variable rootWebConfig comes back as NULL. I have no idea why. Any help or advice would be very much appreciated.

Kind wishes, Patrick

推荐答案

您是否已将appsetting设置为:
Have you set appsetting as:
<appsettings>
     <add key="XmlFilePath" value="C:\yourpath here" /> 
</appsettings> 


如果已设置,则调试WebConfigurationManger对象上的值.


If it is already set, then debug the value on WebConfigurationManger object.


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

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