C # Reading configuration settings

I have a C # A class library that has some configuration options in App.config, I access them using

Method1()
{
string connectionString = ConfigurationManager.AppSettings["ConnectionString"];
}

But when I call method 1 () from my ASP ASP web project, it cannot find the configuration settings in class library A

Any idea what is going on here?

+3
source share
5 answers

, .Net, . . , app.config. - - ( - web.configs), app.configs, , ( winforms, MyWinformsApplication.exe.config; - ASP.Net, . confiog - web.config...

+4

web.config. , , ConfigurationManager.

+2

. exe,

+2

, OpenExeConfiguration:

string exePath = "<full path and name of the app .exe file>";

System.Configuration.Configuration otherConfig = 
     ConfigurationManager.OpenExeConfiguration(exePath);

.exe - web.config(, appSettings) , , .

appSettings :

AppSettingsSection otherAppSettings = otherConfig.AppSettings;

MSDN .

+2

-.

0

Source: https://habr.com/ru/post/1726809/


All Articles