IIS Deployment with Sub Applications : Web.Config parent dependency override
Recently when deploying an application out to IIS we had the need to deploy a sub application within the same domain. Essentially, what we were trying to do was make the sub application an extension of the parent application, but live in separate app pools and the code base would be kept separate as well.
This is simple to set up in IIS, however, when we tried to deploy the second sub application we got this reoccurring error when we tried to hit www.awesomeApp.com/subAwesomeApp.
Server Error in ‘/subAwesomeApp Application.
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: Could not load type ‘AwesomeApp.UpdatePanel’.
The error goes on to tell the file and location within the file which is causing the error to be thrown. You’ll notice here that it is your parent application’s web.config. But why are we getting references to the parent application within the sub application when we wanted to keep them as separate as possible?
This is because, by design, when IIS sets up a site you must provide a web.config file with the application you are deploying. And when you add a virtual directory or application within this site, which has a web.config of it’s own, whatever that sub application is missing in its config file, IIS will automatically try and insert that reference into the sub application’s config and thus, when we try and load the sub app we get an unable to find the reference in the parent application. Which in this case is the UpdatePanel of AwesomeApp.
Luckily there is a simple solution to this issue.
In the parent application’s web.config find the <system.web> and <system.webServer> tags. All we’re going to do here is wrap each of these tags with the following tags.
<location path="." inheritInChildApplications="false"><system.web>...(config content)...</system.web></location><location path="." inheritInChildApplications="false"><system.webServer>...(config content)...</system.webServer></location>
Once you have this in place recycle your app pools and you should now be able to readily access your sub application.