Reputation: 3220
When using OWIN in the IIS integrated pipeline, I want to add UseStaticFiles
to my component. In the Startup class of my app, I have configured this like so:
var filesystem = new PhysicalFileSystem("./Scripts");
app.UseStaticFiles(new StaticFileOptions { RequestPath = new PathString("/files"), FileSystem = filesystem });
To get this working, I need to convince IIS to handle the request to /files/myfile.js
to ASP.NET, so my OWIN component can handle it.
The RAMMFAR method somehow doesn't work for me, but I found out that
<add name="MyStaticFiles-Handler" path="/files/*" verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
will do the trick. However, when I request /files/does-not-exist.js
, I get a status 500 instead of 404.
I have no idea if my TransferRequestHandler is the right method, and whether this 500 is expected. How can I make sure that non-existent files in /files/*
get served as 404 instead of 500?
Upvotes: 0
Views: 275
Reputation: 42020
To make static files work with IIS, enabling RAMMFAR is not enough: you also need to call app.UseStageMarker(PipelineStage.MapHandler)
after calling app.UseStaticFiles(...)
, as indicated on the documentation: http://katanaproject.codeplex.com/wikipage?title=Static%20Files%20on%20IIS&referringTitle=Documentation
var filesystem = new PhysicalFileSystem("./Scripts");
app.UseStaticFiles(new StaticFileOptions { RequestPath = new PathString("/files"), FileSystem = filesystem });
app.UseStageMarker(PipelineStage.MapHandler);
Upvotes: 2