Web.config in a subdirectory in mvc 4

This question seems to have been asked quite a bit, but no one has solved the problem for me. I have an ASP.NET MVC4 application with scope. Inside this area, I have web.config with overridden settings. These settings do not seem to be matched when trying to read them in a controller within an area.

-MyApp -Areas -MyArea -Controllers -MyController -Web.config -Web.config 

In MyApp\Web.config , I have:

 <appSettings> <add key="DefaultDisplayMode" value="Configuration" /> </appSettings> 

In MyApp\Areas\MyArea\Web.config I have:

 <appSettings> <add key="DefaultDisplayMode" value="Review" /> <add key="SubSetting" value="Testing" /> </appSettings> 

In MyController , if I request application settings, I see:

 DefaultDisplayMode: Configuration 

I expect to see:

 DefaultDisplayMode: Review SubSetting: Testing 

I tried with both:

 System.Configuration.ConfigurationManager.AppSettings["..."] System.Web.Configuration.WebConfigurationManager.AppSettings["..."] 

I even tried with the following (above the top) structure with no luck:

 -MyApp -Areas -MyArea -Controllers -MyController -Web.config -Web.config -Web.config 

Does anyone know why my appSettings subdirectory is not working?

+4
source share
1 answer

IIS will download the web.config file based on the URL, not based on the code executed by your routed request.

You can create an empty folder structure that simulates the desired route and adds the configuration file there. If this does not work, you can use the <location> in the main configuration file, but the path in the location tag should also match the URL, not the code.

+2
source

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


All Articles