Sdílet prostřednictvím


AllowSubDirConfig Clarification

The other day, I had a discussion with my fellow coworkers about the impact of the allowSubDirConfig attribute from the VirtualDirectory settings.

https://www.iis.net/configreference/system.applicationhost/sites/site/application/virtualdirectory

allowSubDirConfig:

  • Optional Boolean attribute.
  • Specifies whether IIS looks for Web.config files in content directories lower than the current level (true) or does not look for Web.config files in content directories lower than the current level (false).
  • The default value is true.

The description is quite clear. Basically, IIS will stop looking for Web.config files in sub directories when allowSubDirConfig=false. Actual, it is recommended to set it to false to improve Web Application performance as explained by the article below:
https://blogs.msdn.com/b/carmelop/archive/2012/12/27/iis7-s-performance-slower-than-iis6.aspx

But one should ask what IIS is trying to find. By setting the flag to "false", does it tell IIS to ignore all the web.config files in sub directories or just settings related to IIS?
Indeed, because of the distributed nature of IIS configurations, it is possible that IIS settings being spread across multiple web.config files as described by this article:
https://www.iis.net/learn/get-started/planning-your-iis-architecture/the-configuration-system-in-iis-7

So a Web.config for a subdirectory will be accessed if one of these two conditions is true:

  1. If the directory is set up as a virtual directory, rather than a subdirectory.
  2. If there is a request to an aspx page, which causes asp.net to be involved. Which means that asp.net will apply the settings from <System.web> in the config file even if allowSubDirConfig=false. For settings outside of <System.web>, they will be ignored when allowSubDirConfig=false. They will also be locked out from the configuration editor in IIS manager.

Beware of these rules whenever you want to change allowSubDirConfig setting from "true" to "false" as it may affect the behavior of your website.

Cheers.