MVC Application_PostAuthorizeRequest event not firing when using SignalR
<p>I have an ASP.NET Web API project and I need to access session <code>HttpContext.Current.Session</code> but it's always null in web api</p>

<p>accoriding to <a href="https://stackoverflow.com/questions/9594229/accessing-session-using-asp-net-web-api">Accessing Session Using ASP.NET Web API</a> question I need Application_PostAuthorizeRequest event.</p>

<h2>Global.asax.cs</h2>

<pre><code>public class MvcApplication : System.Web.HttpApplication
    {
        ...

        protected void Application_PostAuthorizeRequest()
        {
            if (IsWebApiRequest())
            {
                HttpContext.Current.SetSessionStateBehavior(SessionStateBehavior.Required);
            }
        }

        private bool IsWebApiRequest()
        {
            return HttpContext.Current.Request.AppRelativeCurrentExecutionFilePath.StartsWith(WebApiConfig.UrlPrefixRelative);
        }

}
</code></pre>

<p>but the problem is <strong><em>Application_PostAuthorizeRequest</em></strong> event never fires.
I recently upgraded my project from MVC4 to MVC5.</p>

<p>I can only catch <strong>Application_AuthenticateRequest</strong> but when I copy the same code in this event it doesn't help and session is still null</p>

<p><strong>Update:</strong></p>

<p>I'm using SignalR to send instant notifications.
I found out when I comment this line <code>app.MapSignalR()</code> eveything works as I expected and I can catch the event.</p>

<p><strong>Startup.cs</strong>:</p>

<pre><code>[assembly: OwinStartup(typeof(Startup))]
namespace UI
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            HttpConfiguration config = new HttpConfiguration();

            ConfigureOAuth(app);

            WebApiConfig.Register(config);
            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
            app.UseWebApi(config);
            //app.MapSignalR(); when i comment this line I can catch the event
        }

        public void ConfigureOAuth(IAppBuilder app)
        {
            OAuthAuthorizationServerOptions OAuthServerOptions = new OAuthAuthorizationServerOptions()
            {
                AllowInsecureHttp = true,
                TokenEndpointPath = new PathString("/token"),
                // TODO expired time hardcoded
                AccessTokenExpireTimeSpan = TimeSpan.FromHours(24),
                Provider = new SimpleAuthorizationServerProvider(),
                RefreshTokenProvider = new SimpleRefreshTokenProvider()
            };

            // Token Generation
            app.UseOAuthAuthorizationServer(OAuthServerOptions);
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());

        }
    }
}
</code></pre>

<p>can somebody explain what's wrong? why when I comment <code>app.MapSignalR()</code> everything works fine.</p>

<p>Any help will be greatly appreciated!</p>