Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Context.User is null in a Signalr 2.0 Hub

I'm using VS 2013 Express and the standard MVC5 template to create a new clean app. Authentication is enabled and I can log into the site just fine. I can see the user context in my controllers, but when I add Signalr I can't get the Hubs to register that authentication has take place.

Context.User in the hub is null. Using Signalr 2.0.2 and all related OWIN packages.

like image 206
WVDominick Avatar asked Feb 10 '14 18:02

WVDominick


1 Answers

The resolution to the program was very simple. In my startup class I had the code in the wrong order.

This is what I had when it wasn't working:

    app.MapSignalR();
    ConfigureAuth(app);

However, this is the correct order to have Signalr work with authentication:

    ConfigureAuth(app);
    app.MapSignalR();

This may be a no-brainer for most, but I think it's an easy mistake to make.

like image 79
WVDominick Avatar answered Oct 13 '22 01:10

WVDominick