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?
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 toapp.UseStageMarker
. For example, after calling:app.UseStageMarker(PipelineStage.Authorize);
calls to
app.UseStageMarker
passingAuthenticate
orPostAuthenticate
will not be honored, and no exception will be thrown. Owin middleware components (OMCs) run at the latest stage, which by default isPreHandlerExecute
. 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With