Context.User is null in a Signalr 2.0 Hub

浪尽此生 提交于 2019-12-19 08:01:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!