Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 811
Trey Mack Avatar asked Aug 01 '14 02:08

Trey Mack


2 Answers

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>
like image 130
Zac Morris Avatar answered Nov 28 '22 10:11

Zac Morris


I had to add the following setting:

<modules runAllManagedModulesForAllRequests="true">

to get the module that Microsoft.Owin.Host.SystemWeb automatically registers to run for routes like *.txt, *.js that IIS was assuming were static files to run through the Owin pipeline.

This setting does have performance implications for actual static files, but this works for me.

like image 23
Trey Mack Avatar answered Nov 28 '22 11:11

Trey Mack