【发布时间】:2016-03-04 11:49:22
【问题描述】:
我在获取一些非常基本的 OWIN 中间件来处理对 IIS 应用程序的所有请求时遇到了一些麻烦。我能够让 OWIN 中间件加载每个页面请求,但我需要它来处理对图像、404、PDF 以及可能在某个主机名下的地址栏中键入的所有内容的请求。
namespace HelloWorld
{
// Note: By default all requests go through this OWIN pipeline. Alternatively you can turn this off by adding an appSetting owin:AutomaticAppStartup with value “false”.
// With this turned off you can still have OWIN apps listening on specific routes by adding routes in global.asax file using MapOwinPath or MapOwinRoute extensions on RouteTable.Routes
public class Startup
{
// Invoked once at startup to configure your application.
public void Configuration(IAppBuilder app)
{
app.Map(new PathString("/*"),
(application) =>
{
app.Run(Invoke);
});
//app.Run(Invoke);
}
// Invoked once per request.
public Task Invoke(IOwinContext context)
{
context.Response.ContentType = "text/plain";
return context.Response.WriteAsync("Hello World");
}
}
}
基本上,无论我请求http://localhost/some_bogus_path_and_query.jpg 还是http://localhost/some_valid_request,所有请求都将通过Invoke 子例程进行路由。
这可以用 OWIN 实现吗?
我已经阅读过 (How to intercept 404 using Owin middleware) 之类的主题,但我没有任何运气。当我真的需要 OWIN 在所有情况下编写 Hello World 时,IIS Express 会不断提供 404 错误,无论资产是否在磁盘上。
此外,我已将 runAllManagedModulesForAllRequests="true" 添加到 web.config 文件中,当我通过 URL 请求图像时,仍然无法触发 OWIN。
【问题讨论】:
-
地图不支持通配符。返回 app.Run 并运行AllManagedModulesForAllRequests。
标签: asp.net asp.net-mvc-4 owin