Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Owin UseStaticFiles not respecting RequestPath

Tags:

owin

**EDIT: NOTE: This appears to be fixed in later versions of the Owin StaticFiles middleware, so if you have this probem, simply upgrade **

My OWIN configuration has this:-

   string root = AppDomain.CurrentDomain.BaseDirectory;
   var staticFilesOptions = new StaticFileOptions();
   staticFilesOptions.RequestPath = new PathString("/foo");
   staticFilesOptions.FileSystem = new PhysicalFileSystem(Path.Combine(root, "web"));
   app.UseStaticFiles(staticFilesOptions);

When I hit /foo/app/app.js I get a 404 error, when I hit /web/app/app.js the file is returned.

How is RequestPath meant to work in conjunction with PhysicalFileSystem?

like image 793
Ian Mercer Avatar asked Mar 13 '14 18:03

Ian Mercer


1 Answers

I tested this code snippet and it works for me from this sample project.

app.UseFileServer(new FileServerOptions()
{
    RequestPath = new PathString("/foo"),
    FileSystem = new PhysicalFileSystem(@".\web"),
});

Make sure you have this in your web.config:

<system.webServer>
    ...
    <modules runAllManagedModulesForAllRequests="true"></modules>
    ...
</system.webServer>
like image 87
Ben Wilde Avatar answered Sep 20 '22 22:09

Ben Wilde