Why is IIS 10 default document not working for a static file?

1.5k views Asked by At

I have an IIS 10 site and I can download document index.html from the root directory without issues. However, when I try to download the same file using the default document feature, I get status code 404.0 and it looks like IIS made no attempt to convert the request from / to /index.html.

My web.config file:

        <defaultDocument enabled="true">
            <files>
                <clear />
                <add value="index.html" />
            </files>
        </defaultDocument>
        <handlers>
            <add name="Static File" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="File" requireAccess="Script" />
            <add name="DefaultDocument" path="*" verb="*" modules="DefaultDocumentModule" resourceType="File" />
        </handlers>
1

There are 1 answers

1
Tim Williams On BEST ANSWER

Ah. Found the issue. My static file handler had resourceType="File", so was only invoked for explicitly named files. It should have been as follows:

        <handlers>
            <add name="Static File" path="*" verb="*" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" resourceType="Either" requireAccess="Script" />
        </handlers>

This appears to be necessary for default document to work.

Using the GUI from IISM it's:

  1. Click the site in the "Connections" tree on the left.
  2. Double click "Handler Mappings" in the panel to the right of tree.
  3. Double click the static file handler (or add it if it's not there).
  4. Click "Request Restrictions..."
  5. On the Mapping tab, click "Invoke handler only if request is mapped to:" then click "File or folder" and OK your way back.