This is the hierarchy for ASP.NET configuration. Maybe this could help understanding which settings overwrite each other.
Server
Machine.config: The Machine.config file contains the ASP.NET schema for all of the Web applications on the server. This file is at the top of the configuration merge hierarchy.
Root Web
Web.config: The Web.config file for the server is stored in the same directory as the Machine.config file and contains default values for most of the system.web configuration sections. At run time, this file is merged second from the top in the configuration hierarchy.
Web site
Web.config: The Web.config file for a specific Web site contains settings that apply to the Web site and inherit downward through all of the ASP.NET applications and subdirectories of the site.
ASP.NET application root directory
Web.config: The Web.config file for a specific ASP.NET application is located in the root directory of the application and contains settings that apply to the Web application and inherit downward through all of the subdirectories in its branch.
ASP.NET application subdirectory
Web.config: The Web.config file for an application subdirectory contains settings that apply to this subdirectory and inherit downward through all of the subdirectories in its branch.
Client application directory
ApplicationName.config: The ApplicationName.config file contains settings for a Windows client application (not a Web application).
Understanding which ASP.NET files and folders are inherited through folders and applications is very important for development and troubleshooting.
Here is a short summary:
- web.config files inherit all the way down the tree, past all application boundaries.
- global.asax only lives within its application
- /bin and the /app_{folders} only live within their application
So, this means that anything set in the root web.config file will inherit down the entire site, even if some folders are marked as applications.
Where this gets messy is if the web.config file has references to assemblies but sub-applications don't have those assemblies. For example, let's say that you have a HTTP Module configured in the root of the site and referenced from the site web.config file. If you have a sub-application called /subfolder which is marked as an application, then /subfolder will attempt to load the HTTP Handler from /subfolder/bin. Since it doesn't exist, an error will be thrown.
There are multiple ways around this. Probably the cleanest if the HTTP Handler isn't needed in /subfolder is by 'removing' the reference by adding a clause in the /subfolder/web.config file. You can do this with . Here is an example of how to remove a HTTP Module in a subfolder:
<httpModules>
<remove name="ErrorLog"/>
</httpModules>
Here is what the site web.config might look like:
<httpModules>
<add name="ErrorLog" type="GotDotNet.Elmah.ErrorLogModule, GotDotNet.Elmah, Version=1.0.5527.0, Culture=neutral, PublicKeyToken=978d5e1bd64b33e5" />
</httpModules>print("code sample");