IIS7 default document for urlMapped url throws 403 error

default-documentiis-7rewrite

Hopefully this all makes sense:

I have a Web Application project against an IIS7 server that is "theme-able" using different master pages.

As a result of what I am trying to do, the root of the project has no aspx files, so I am using the web.config's ability to rewrite "~/default.aspx" to "~/themes/a/default.aspx"

this works great as long as i type in "http://www.mysite.com/default.aspx", but typing just "http://www.mysite.com" results in a "403 – Forbidden: Access is denied" error

I was hoping that the combination of urlMapping and default document would be smart enough to handle this, but it's not

<system.webServer>
      <defaultDocument enabled="true">
          <files>
              <clear />
              <add value="default.aspx"/>
          </files>
      </defaultDocument>
</system.webServer>

i also tried

<system.webServer>
      <defaultDocument enabled="true">
          <files>
              <clear />
              <add value="~/themes/a/default.aspx"/>
          </files>
      </defaultDocument>
</system.webServer>

to no avail

I was hoping a browser would come in without a document defined, IIS7 would assume it was default.aspx, and then the urlMapping would map it accordingly, but nope

any pointers? I've read a ton of posts here with similar issues, but not the exact issue

Best Answer

You can handle both scenario's of http://www.mysite.com/ and http://www.mysite.com/default.aspx with one single URL rewrite rule.

<rule name="Rewrite to theme folder">
    <match url=".*" />
    <conditions logicalGrouping="MatchAny">
        <add input="{URL}" pattern="^/default\.aspx$" />
        <add input="{URL}" pattern="^/$" />
    </conditions>
    <action type="Rewrite" url="/themes/a/default.aspx" logRewrittenUrl="true" />
</rule>

The default document can only be set to file name. You can't specify a folder. IIS will probably ignore your entry as it can't open it as a file. The 403 error is occurring because there is probably no other default document specified (or found) and directory browsing is disabled (by default).

Related Topic