Owin Stage Markers

余生长醉 提交于 2019-12-01 19:22:30

问题


Given this in my app startup ...

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


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

... why does the PostAuthenticate code execute before the Authenticate code?

I don't mean "why does the first app.use get called before the second app.use" I mean: Why does the first invoke get called before the second given that that the second should be happening earlier in the request pipeline?

EDIT

Related to this problem: How am I getting a windows identity in this code?


回答1:


It's by design, according to the documentation: https://www.asp.net/aspnet/overview/owin-and-katana/owin-middleware-in-the-iis-integrated-pipeline.

In the section Stage Marker Rules, you could read the following:

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.




回答2:


It seems that even contrary to the documentation events in IIS are hooked up and processed in the order they are configured rather than in the order they should appear in the request lifecycle.

This feels like a bug in the owin request lifecycle to me but hey, I got my problem solved.



来源:https://stackoverflow.com/questions/37165192/owin-stage-markers

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!