Access Web.config settings in Asp.Net Core App?

I kinda found the solution. The key to figuring it out was realizing that the AppDomain.CurrentDomain.SetupInformation.ConfigurationFile property wasn’t pointing to the web.config file but rather to the exe.config file for the executable running the website. Remember, under .net core, the website runs in its own process and it has its own exe.

So the config model that .Net 4.x uses with the ConfigurationManager is more like that of a desktop app than a 4.x web application. By that I mean that it’s looking at the exe.config not the web.config.

Then I noticed that the Asp.Net Core Web Project (using the full framework) contains an app.config file much like a desktop app would. And it turns out that if you put your .net 4.x application config settings in that file they will get placed in the exe.config file when the exe is generated, whether for debug or for release. Just exactly like it works with a win forms app for example.

So the way to utilize the ConfigurationManager in an asp.net core web application that targets the full framework is to put the application setting in the app.config file rather than the web.config file. The ConfigurationManager will find them no problem.

enter image description here

While this explains a lot, it still doesn’t provide that ability to actually put those settings in the web.config and access them via the ConfigurationManager. But I’m beginning to believe that’s not possible in a asp.net core web application even if it is targeting the full framework.

Leave a Comment