无法读取类库的App.config值 [英] Unable read App.config values from Class Library

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

问题描述

这可能是简单回答的问题,但我奋力化解。

This may be the simple question to answer, but I am struggling to resolve.

的Web.config 在我的Web应用程序下面的值。

I have Web.config with the following values in my Web Application.

<appSettings>
    <add key ="FirstName" value ="Prasad"/>
    <add key ="LastName" value ="Kanaparthi"/>
</appSettings>

的App.config 在我的类库(说库)下面的值。

I have App.config with following value in my Class Library (Say Lib).

<appSettings>
    <add key ="FullName" value ="Prasad Kanaparthi"/>
</appSettings>

类库(库)是可插拔的组成部分,我已经加入我的Web应用程序的类库(库)的参考。

The class library(Lib) is pluggable component, I have added the Class Library(Lib) reference in my Web Application.

我在我的类库(库)以下code。当我在我的web应用程序中创建实例 GetAppSettings 我可以看到下面的反应。

I have the below code in my Class Library(Lib). When i create instance for GetAppSettings in my web application i can see below responses.

namespace Lib
{
    public class GetAppSettings
    {
        public GetAppSettings()
        {
            var FirstName = ConfigurationManager.AppSettings["FirstName"];  // O/P : Prasad
            var MiddleName = ConfigurationManager.AppSettings["LastName"];  // O/P : Kanaparthi

            var FullName = ConfigurationManager.AppSettings["FullName"];    // O/P : null
        }
    }
}

问题是我怎么能读全名的App.config 这是类库(库)。

注意:既然我是库可插入组件,因此,消费者可以修改全名的自己。我无法从的App.config 合并值 Web.confing

Note: Since my Lib is pluggable component, So the consumers can change the FullName of their own. I cannot merge values to Web.confing from App.config.

推荐答案

您必须合并这两个配置部分,并把你的应用程序的主配置文件中的所有设置。在Web applciation的情况下,这将是的web.config

You have to merge both configuration sections and place all settings in the main configuration file of your application. In case of the web applciation it would be the web.config.

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

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