ConfigurationManager.AppSettings越来越空? [英] ConfigurationManager.AppSettings getting null?

查看:517
本文介绍了ConfigurationManager.AppSettings越来越空?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有意识到:我有一个单独的类库一个web.config和我读的web.config从不同的万维网应用程序appsetting

我使用VS2010的目标框架3.5

我不知道什么是错在这里,但我得到当我试图让 ConfigurationManager.AppSettings [STOREID];

 私人字符串_storeid = GetStoreId;公共静态字符串GetStoreId
{
    得到
    {
        返回ConfigurationManager.AppSettings [STOREID];
    }
}

Web.confid:

 <&的appSettings GT;
    <添加键=STOREIDVALUE =123/>
< /的appSettings>


解决方案

是你在上面使用一个单独的类库到您的主asp.net贴库吗?code

如果你是,你已经添加了一个app.config这个库上方,然后ConfigurationManager中不读取正确的文件,因为这将期待您的asp.net库中的web.config文件发布的设置。

i did not realize that: i have a web.config in a separate class library and i was reading the web.config appsetting from different web applicaiton.

i am using VS2010 target framework 3.5

i dont know what is wrong here but i am getting null when i try to get ConfigurationManager.AppSettings["StoreId"];

private string _storeid = GetStoreId;

public static string GetStoreId
{
    get
    {
        return ConfigurationManager.AppSettings["StoreId"];
    }
}

Web.confid:

<appSettings>
    <add key="StoreId" value="123" />
</appSettings>

解决方案

Is the code you posted above using a separate class library to your main asp.net library?

If you are and you have added an app.config to this library with the settings posted above then the ConfigurationManager is not reading the right file as this will look to the web.config file for your asp.net library.

这篇关于ConfigurationManager.AppSettings越来越空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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