I have start up code in my Web API project that attempts to read values from the web.config file which is published inside the bin directory by default. Because the application initialization point is Global.asax, there is no web.config at this level so I need to figure out how to reference it down in the bin folder.
Here is the root of my IIS directory:
Anytime I try to read values from the web.config file using ConfigurationManager.AppSettings
they come back null. It's only when I move the web.config up out of the bin folder and into the root directory will the values be found.
I tried adding some code that suggested it would force the path to the correct default location (inside the bin folder) before trying to read a value but that doesn't work either:
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// Fix web.config location
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin\\web.config");
AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", path);
var appId = ConfigurationManager.AppSettings["ApplicationId"];
}
}
Is there a way to force the path to the web.config living inside the bin folder?