Owin Stage Markers

Given this when starting the application ...

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

... why is the PostAuthenticate code executed before the Authenticate code?

I do not mean "why the first app.use is called before the second app.use". I mean: why does the first call cause the call before the second, given that the second should happen earlier in the pipeline request?

EDIT

Related to this problem: How to get the Windows ID in this code?

+5
source share
2 answers

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

In the "Stage Marker Rules" section, you can read the following:

The OWIN pipeline and IIS pipeline are ordered, so the calls to app.UseStageMarker should be fine. You cannot set an event handler in an event that precedes the last event registered on app.UseStageMarker . For example, after a call:

 app.UseStageMarker(PipelineStage.Authorize); 

calls to app.UseStageMarker Authenticate or PostAuthenticate transfer will fail, and no exception will be thrown. Owin middleware (OMC) components work in the final step, which is PreHandlerExecute by default. Stage markers are used to make them work earlier. If you specify stage markers out of order, we round to an earlier marker. In other words, adding a scene marker says "Run no later than step X". OMC starts early in the marker, added after them in the OWIN pipeline.

+5
source

It seems that even contrary to documentation events, IIS hooks up and processes in the order in which they are configured, and not in the order in which they should appear in the request life cycle.

This seems like a bug in the owin request life cycle for me, but hey, I solved the problem.

0
source

All Articles