欧文阶段标记

Owin Stage Markers

鉴于此在我的应用启动时...

app.Use((context, next) =>
{
   return next.Invoke();
}).UseStageMarker(PipelineStage.PostAuthenticate);


app.Use((context, next) =>
{
   return next.Invoke();
}).UseStageMarker(PipelineStage.Authenticate);

...为什么PostAuthenticate代码在Authenticate代码之前执行?

我不是说 "why does the first app.use get called before the second app.use" 我的意思是:既然第二次调用应该在请求管道中更早发生,为什么第一次调用在第二次调用之前被调用?

编辑

与此问题相关:

似乎与文档相反,IIS 中的事件是按照它们配置的顺序连接和处理的,而不是按照它们在请求生命周期中应该出现的顺序。

这对我来说就像是 owin 请求生命周期中的一个错误,但是嘿,我的问题已经解决了。

根据文档,这是设计使然:https://www.asp.net/aspnet/overview/owin-and-katana/owin-middleware-in-the-iis-integrated-pipeline

阶段标记规则部分,您可以阅读以下内容:

The OWIN pipeline and the IIS pipeline is ordered, therefore calls to app.UseStageMarker must be in order. You cannot set the event handler to an event that precedes the last event registered with to app.UseStageMarker. For example, after calling:

app.UseStageMarker(PipelineStage.Authorize);

calls to app.UseStageMarker passing Authenticate or PostAuthenticate will not be honored, and no exception will be thrown. Owin middleware components (OMCs) run at the latest stage, which by default is PreHandlerExecute. The stage markers are used to make them to run earlier. If you specify stage markers out of order, we round to the earlier marker. In other words, adding a stage marker says "Run no later than stage X". OMC's run at the earliest stage marker added after them in the OWIN pipeline.