Search code examples
iisowinstatic-fileskatana

Microsoft.Owin.StaticFiles works in console host but I get a 404 in IIS on file requests


I have Microsoft.Owin.FileServer (v2.1.0) set up in my Owin pipeline, and setting up FileServerOptions with EnableDirectoryBrowsing = true works great for showing the directory contents in both my console host and iisexpress.

It's when I try to view a particular file (so, the StaticFiles part) I have problems in iisexpress. Still works great in the console host, but in iisexpress I get a 404:

HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Most likely causes:
- The directory or file specified does not exist on the Web server.
- The URL contains a typographical error.
- A custom filter or module, such as URLScan, restricts access to the file.

I do have the latest Microsoft.Owin.Host.SystemWeb referenced in the web host.


Solution

  • Adding <modules runAllManagedModulesForAllRequests="true"> didn't work for me (VS2013, IIS Express).

    Forcing all requests to use the Owin pipeline did:

    (in web.config)

    <configuration>
      <system.webServer>
        <handlers>
          <add name="Owin" verb="" path="*" type="Microsoft.Owin.Host.SystemWeb.OwinHttpHandler, Microsoft.Owin.Host.SystemWeb"/>
        </handlers>
      </system.webServer>
    </configuration>