This may be the simple question to answer, but I am struggling to resolve.
I have Web.config with the following values in my Web Application.
<appSettings>
<add key ="FirstName" value ="Prasad"/>
<add key ="LastName" value ="Kanaparthi"/>
</appSettings>
I have App.config with following value in my Class Library (Say Lib).
<appSettings>
<add key ="FullName" value ="Prasad Kanaparthi"/>
</appSettings>
The class library(Lib) is pluggable component, I have added the Class Library(Lib) reference in my Web Application.
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
}
}
}
The Question is how can i read FullName from App.config which is Class Library (Lib).
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.
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.