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:
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.