OWIN middleware PostAuthenticate event never fires
<p>I have a simple example of OWIN middleware and I want to tap into the <code>PipelineStage.PostAuthenticate</code> stage via:</p>

<pre><code>app.UseStageMarker(PipelineStage.PostAuthenticate);
</code></pre>

<p>The problem I have is that it never seems to hit the <code>PostAuthenticateRequest</code> event, even though the user is authenticated.</p>

<p>It always prints:</p>

<pre><code>Current IIS event: AuthenticateRequest Msg: Should be Auth
Current IIS event: AuthenticateRequest Msg: Should be PostAuth
</code></pre>

<p>I can work around this by using the events in <code>Global.asax</code> or an <code>IHttpModule</code> but I would rather use the OWIN Pipleine.</p>

<p><strong>Simple example:</strong></p>

<pre><code>using System;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
using System.Web;
using System.IO;
using Microsoft.Owin.Extensions;
[assembly: OwinStartup(typeof(owin2.Startup))]
namespace owin2
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            app.Use((context, next) =&gt;
            {
                PrintCurrentIntegratedPipelineStage(context, "Should be Auth");
                return next.Invoke();
            });
            app.UseStageMarker(PipelineStage.Authenticate);
            app.Use((context, next) =&gt;
            {
                PrintCurrentIntegratedPipelineStage(context, "Should be PostAuth");
                return next.Invoke();
            });
            app.UseStageMarker(PipelineStage.PostAuthenticate);

        }
        private void PrintCurrentIntegratedPipelineStage(IOwinContext context, string msg)
        {
            var currentIntegratedpipelineStage = HttpContext.Current.CurrentNotification;
            context.Get&lt;TextWriter&gt;("host.TraceOutput").WriteLine(
                "Current IIS event: " + currentIntegratedpipelineStage
                + " Msg: " + msg);
        }
    }
}
</code></pre>

<p>Taken from:
<a href="http://www.asp.net/aspnet/overview/owin-and-katana/owin-middleware-in-the-iis-integrated-pipeline" rel="nofollow">OWIN Middleware in the IIS integrated pipeline</a></p>

<p>The app is configured to use windows:</p>

<p>Anonymous Authentication = false</p>

<p>Windows Authentication = true</p>

<pre><code>&lt;configuration&gt;
  &lt;system.web&gt;
    &lt;compilation debug="true" targetFramework="4.5.2"/&gt;
    &lt;httpRuntime targetFramework="4.5.2"/&gt;
    &lt;authentication mode="Windows"&gt;&lt;/authentication&gt;
  &lt;/system.web&gt;
  ...
</code></pre>