**编辑:注意:这似乎在 Owin StaticFiles 中间件的更高版本中得到修复,因此如果您有此问题,只需升级 **
我的 OWIN 配置有这个:-
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);
当我点击
/foo/app/app.js
当我点击 /web/app/app.js
时,我收到 404 错误文件被返回。怎么样
RequestPath
旨在与 PhysicalFileSystem
一起工作?
最佳答案
我测试了这个代码片段,它对我有用 this sample project .
app.UseFileServer(new FileServerOptions()
{
RequestPath = new PathString("/foo"),
FileSystem = new PhysicalFileSystem(@".\web"),
});
确保你的 web.config 中有这个:
<system.webServer>
...
<modules runAllManagedModulesForAllRequests="true"></modules>
...
</system.webServer>
关于Owin UseStaticFiles 不尊重 RequestPath,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22387555/