IIS 7 and Above
URL Rewrite Module
Rewrite rule not being applied when in "main" web.config
Last post Apr 03, 2012 05:24 PM by jbrandhorst
Mar 29, 2012 02:28 PM|jbrandhorst|LINK
I've been struggling with trying to apply a rewrite rule to my site, running IIS7 on Windows Server 2008, hosting an ASP site running in "Classic" Managed Pipeline Mode(Microsoft .NET Framework Version:2.0.50727.4016; ASP.NET Version:2.0.50727.4223). Hopefully
my full explanation of the issue makes sense.
In my dev environment, our "main" web site is nested a few folders deep under the Sites folder on IIS Manager, as we have several other sites and services elsewhere. That site has a web.config, and there are no other web.config files in any of the directories
above it in the folder hierarchy. When that main site is deployed to test/production web servers, it is the only site deployed to IIS on those boxes, and is the only site under "Default Web Site" in the Sites directory in IIS Manager. The web.config file in
the root directory for that site is the only web.config that exists on these boxes.
In my dev environment, if I create a URL rewrite rule using the GUI and apply it at any directory level higher than my main web site, it will create a web.config in the given directory that has only a system.webServer section with the rewrite rule I just
created. This rewrite rule works for the main site that is in a subdirectory from where this newly created web.config exists. However, if I create a rewrite rule at the root directory level for my main site, it adds the rewrite rule to the site's web.config
(as expected), but the rewrite rules do not take effect. Similarly, if I add them on my test/prod servers at the site level so that they are added to the site's web.config, the rewrite rules also are not applied.
In test/prod I need to have the rewrite rules applied at the location of my main site's web.config, as it's the only location where I can place a web.config file.
Has anybody else encountered an issue like this? Any suggestions? Thanks.
url rewrite 2.0
Apr 02, 2012 07:02 AM|Mamba Dai - MSFT|LINK
Sorry for disabling to grasp your question exatctly.
It's seems a configuration hierarchy issue.
A configuration hierarchy is defined and calculated for the configuration settings of the system. The hierarchy starts at machine.config, then progresses to the root web.config file, followed by applicationHost.config. From then on, any optional web.config
file that is located at the site, application or virtual directory level is added and applied to the hierarchy. At the end, the properties inherit from parent to child file from machine.config down to the last web.config file (if any) and the effective configuration
is calculated for a given path.
The inheritance behavior is done by default. Any setting at a lower level in the hierarchy overrides a parent setting defined in a file above the current level. However, going further down the hierarchy, the scope of configuration is more limited. Where
as the machine.config, root web.config and applicationHost.config files' settings apply to everything in the system, optional web.config files' settings only apply to the current location and below (whether it is a site, application or virtual directory).
For more inforamtion about Configuration Hierarchy please refer to this:
BTW, if this still doesn't work for your problem, please clarify your question
Apr 03, 2012 05:24 PM|jbrandhorst|LINK