IIS 7 – Single Page Application URL issues when aliased

asp.net-mvciis-7

A client of ours has the following setup under IIS

Sites
 - applications (binds to http://applications.domain.com)
  - app1
  - app2

app1 and app2 are both .NET Single Page Applications (combination of .NET MVC and .NET Web API).

The applications are under the C:\inetpub\applications\ folder and both have been converted to applications. Thus app1 is available under the following URL http://applications.domain.com/app1 and app2 is available under http://applications.domain.com/app2

The problem I'm running into is that all the AJAX routes are relative to the root (/) route and are therefore non existant e.g. http://applications.domain.com/api/products doesn't throws a 404 since the route is actually http://applications.domain.com/app1/api/products.

Is there an IIS setting that will allow me to make this work short of re-writing all my AJAX calls with the prefix? Or is there a different way I can configure this kind of setup under IIS? Thanks.

Best Answer

What you want to do is put both apps in their own virtual directories -- then most of the asp.net calls will get the correct document root and things will be righter with the world.

To do so:

  1. make a fake document root and fake website -- iis7 needs someplace to stash a web.config file and this should be unique to this app. I'd use something like c:\inetpub\applications\deadroot; add an IIS site looking at this folder.
  2. Add a virtual application for app1 pointed at app1's folder inside this site
  3. Add a virtual application for app2 pointed at app2's folder inside this site

Each will then stand on it's head.