How to use the location path in web.config to set a default document in IIS7

default-documentiis-7

I have a multi-tennant website that I'm migrating from IIS5 on Win 2000 to IIS7 on Win Server 2008 64bit.

Every tennant has their own domain name that they point to the application server's IP address.

Then we set up a site in IIS for each domain name and set the physical path to the path where our (classic) ASP files are located.

For each site, I want to set up a default document that runs an ASP file and passes the CompanyID in the querystring.

E.g.
www.site1.com would call Connect.asp?CompanyID=425
www.site2.com would call Connect.asp?CompanyID=426
etc

To achieve this on IIS7, I have a web.config file in the root physical path of the ASP files which looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<location path="www.site1.com">
    <system.webServer>
    <defaultDocument>
        <files>
            <add value="Connect.asp?CompanyID=425" />
        </files>
    </defaultDocument>
    </system.webServer>
</location>
<!-- a location entry for every other website here... -->
<location path=".">
<system.webServer>
    <defaultDocument>
        <files>
            <add value="Connect.asp?CompanyID=1" />
        </files>
    </defaultDocument>
</system.webServer>
</location>
</configuration>

This is not working – all the sites are going to the CompanyID=1 entry.

Can someone point out what I'm doing wrong?

I've tried setting the path attribute to

  1. the domain name
  2. the friendly name of the site in IIS

either way it doesn't work.

Best Answer

I found the solution at this link on the iis forums

You can put the configuration in location tags in applicationhost.config rather than in web.config file - by doing something like this from the command line:

%windir%\system32\inetsrv\appcmd.exe set config "MySite1" -section:system.webServer/defaultDocument -+files.[value='newdoc.aspx'] -commitpath:apphost

  • MySite1 is the friendly name of the site in IIS (the site name you see in the tree on the left)
  • newdoc.aspx is the name of your default document for that site (you can specify a querystring)

So for the example that I posted above, I ran this command for each of my sites

%windir%\system32\inetsrv\appcmd.exe set config "MySite1 - www.site1.com" -section:system.webServer/defaultDocument -+files.[value='Connect.asp?CompanyID=425'] -commitpath:apphost

and

%windir%\system32\inetsrv\appcmd.exe set config "MySite2 - www.site2.com" -section:system.webServer/defaultDocument -+files.[value='Connect.asp?CompanyID=426'] -commitpath:apphost

When you go to the default document program for the 2 sites in the IIS7 management program, you will see the different default documents set for the 2 sites.