问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/21684605/context-user-is-null-in-a-signalr-2-0-hub