In SignalR, i experience that Context.User is suddenly turning into null value and also it is sometimes completely null but this should never be happen because only Authorized users can access the hub.
What is reason of these strange behaviors ? I am using SignalR 2.0 with ASP.NET MVC 4 on Visual Studio 2013.
[Authorize]
public class FeedHub : Hub
{
public override Task OnConnected()
{
var name = Context.User.Identity.Name;// here is User is not null
var user = GetUser();// but it is changing to null inside this private method
return base.OnConnected();
}
private User GetUser()
{
var name = Context.User.Identity.Name;// here is User property is null and throws exception
return null;//
}
public override Task OnDisconnected()
{
//In here Context.User property is sometimes null but in my opinion this should never be null
// because Hub is protected by Authorize attribute.
return base.OnDisconnected();
}
}
This is confirmed bug in 2.0.2
https://github.com/SignalR/SignalR/issues/2753
Currently it is resolved but not included in official release.
Your options are:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With