欧文 app.use 对比 app.run 对比 app.map

OWIN app.use vs app.run vs app.map

app.useapp.runapp.mapOwin有什么区别?什么时候用什么?看文档的时候不是很直接

app.use 将一个中间件插入到管道中,这需要您通过调用 next.Invoke() 来调用下一个中间件。

app.run 插入一个没有 next 的中间件,所以它只是 运行s.

使用 app.map 您可以映射路径,仅当请求路径与您映射的模式匹配时,每个请求在 运行 时间评估到 运行 某些中间件。

有关 use and run and map 的详细信息,请参阅文档

在处理请求时,我们使用 IApplicationBuilder。我们有四种方法可用于与请求交互:

  • 使用
  • 运行
  • 地图
  • 地图时

这些被称为请求代表

使用:

Adds a middleware to the application pipeline and it can either pass the request to next delegate or it can end the request (short- circuit request pipeline). It is the most commonly used method to interact with middleware.

地图

We use Map to connect a request path with another middleware. That middleware can use any of the other mentioned request delegates.

MapWhen

Behaves almost the same as Map except that we can specify the detailed condition by using a HttpContext object. We could check for URL, headers, query strings, cookies, etc).

运行

Generate a response and short-circuit the request

另请阅读此 article 了解更多信息。