Web.config inheritance tip…
Mainly writing this entry so I don’t spend hours looking for a solution when I need it again, since I tend to forget rather quickly how exactly I solved a problem. In this case, I have a website that is ASP.NET 3.5 and a folder which contains a different .NET application. I understand that the web.config in the root of the site, will cascade down into the applications within by default. What if our application within uses different settings… how do we prevent the settings in the root to affect the child applications?
Well, I learned that this can be accomplished in two parts. First there is a somewhat undocumented trick to instruct IIS that we do not want the settings to be inherited by child applications. You will need to wrap your <system.web> tag in a new tag, named <location> with the attributes as shown below:
<location path="." inheritInChildApplications="false" > <system.web> [...] </system.web> </location>
Note that this will show a red squigly line in Visual Studio since the inheritInChildApplications attribute is unknown to VS.
Now, this only seems to work with <system.web>…what if we need to do the same with, let’s say the <configsections>…? Assume we are pointing to System.Web.Extension dll, version 3.5 in the root and we want to point to a version 1.1 in the childApplication? In that case, we cannot use the <location> trick mentioned above.
Instead, we can to do a runtime binding redirect in the web.config of the childApplication as shown below:
<configuration> [...] <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35"/> <bindingRedirect oldVersion="188.8.131.52" newVersion="1.0.61025.0"/> </dependentAssembly> </assemblyBinding> </runtime> </configuration>