Monday, 25 March 2013

IIS - Nested Web Applications & web.config dependency

Question:

I tried deploying a child web application in IIS7 as a virtual directory, but I could not get it working as it was throwing exceptions as an assembly was not found. The issue remained the same even when the virtual directory was converted as an Application. The child application has no reference to the missing assembly, but the parent application does use it and the assembly is found in the parent bin folder. How to break this web.config dependency between the parent and child web applications?

Question by: Sangeetha Sundaram

Response:

The dependency between the parent child web applications can be separated using the <location> config element in the parent web.config. Wrap the <system.web> node and the <system.webserver> elements within a <location> element and specify the inheritInChildApplications attribute to false. For example:


<location path="." inheritInChildApplications="false">
    <system.web>
       <!-- ... -->
    </system.web>
</location>


<location path="." inheritInChildApplications="false">
    <system.webServer>
       <!-- ... -->
    </system.webServer>
</location>


The location element extends the flexibility to have different system.web and system.webserver nodes for different folders within the website. When the inheritInChildApplications attribute is set to true, the parent web.config will be inherited in all the locations including applications within the parent website.

This location element can also be used to specify different configuration attributes for different resources. For example the use of the location element as below will set the uploaded file size to 128 KB for this specific page alone.


<configuration>
  <location path="UploadPage.aspx">
    <system.web>
      <httpRuntime maxRequestLength="128"/>
    </system.web>
  </location>
</configuration>


For more information on the location element check out the following reference links:

Breaking parent web.config dependencies in sub applications

No comments:

Post a comment