The Katana static file middleware can be used on both self-host (HttpListener) and web-host (SystemWeb). However, when running on SystemWeb/IIS, some additional configuration may be required.

IIS has a native static file module that is optimize to skip other portions of the pipeline if it sees file paths that do not match other handlers (e.g. not aspx). This means that the directory browser middleware is likely to work, but then the static file middleware may be bypassed in favor of the native static file module.


Here are two changes you need to make to ensure the static file middleware runs instead of the native static file module.

In your web.config add:
      <modules runAllManagedModulesForAllRequests="true" />

This tells IIS not to skip the managed Asp.Net modules even if the native static file module thinks it has a match.

Also, add the following stage marker AFTER your static file middleware (in namespace Microsoft.Owin.Extensions):

See the following article for more details about working with stage markers:


If you don't want to use the above approach, either of the following options should also work:

Configure the static file middleware so that the url path does not directly match the physical path.
app.UseFileServer(new FileServerOptions
  FileSystem = new PhysicalFileSystem(".\\public"),
  RequestPath = new PathString("/files"),

This causes requests for /files/myfile.txt to be mapped to .\public\myfile.txt, bypassing the native static file module's url matching.

The other alternative is to remove the native static file module, either via the IIS configuration page or the applicationhost.config file.

Last edited Dec 10, 2014 at 7:27 PM by Tratcher, version 6


EyalShilony Aug 18, 2014 at 3:36 AM 
I tried to do everything here and it didn't go so well, I also tried to Install Microsoft.Owin.Host.IIS package but it gave me bunch of exceptions so what I ended with is adding the OwinHttpHandler to the web.config like this.

<modules runAllManagedModulesForAllRequests="false" />
<remove name="StaticFile" />
<add name="OWIN" path="*" verb="*" type="Microsoft.Owin.Host.SystemWeb.OwinHttpHandler" />

jchannon Jul 9, 2014 at 12:44 PM 
This is wrong and lost me hours! If you're using SystemWeb you need the web.config changes and UseStageMarker even if you use UseFileServer!!!! If you use Helios/Microsoft.Owin.Host.IIS you dont need the web.config/UseStageMarker bits