I found a solution using the Microsoft.Owin.StaticFiles nuget package:
First, make sure this is in your web configuration, so static file requests are sent to OWIN:
<system.webServer> ... <modules runAllManagedModulesForAllRequests="true"></modules> ... </system.webServer>
Then in your download setup method add this code:
// app is your IAppBuilder app.Use(typeof(MiddlewareUrlRewriter)); app.UseStaticFiles(); app.UseStageMarker(PipelineStage.MapHandler);
And here is MiddlewareUrlRewriter:
public class MiddlewareUrlRewriter : OwinMiddleware { private static readonly PathString ContentVersioningUrlSegments = PathString.FromUriComponent("/content/v"); public MiddlewareUrlRewriter(OwinMiddleware next) : base(next) { } public override async Task Invoke(IOwinContext context) { PathString remainingPath; if (context.Request.Path.StartsWithSegments(ContentVersioningUrlSegments, out remainingPath) && remainingPath.HasValue && remainingPath.Value.Length > 1) { context.Request.Path = new PathString("/Content" + remainingPath.Value.Substring(remainingPath.Value.IndexOf('/', 1))); } await Next.Invoke(context); } }
As an example, this allows the GET request /Content/v/1.0.0.0/static/home.html to get the file in /Content/static/home.html .
UPDATE: Added app.UseStageMarker(PipelineStage.MapHandler); after other app.Use methods, as required to do the job. http://katanaproject.codeplex.com/wikipage?title=Static%20Files%20on%20IIS
source share