W SignalR doświadczam, że Context.User nagle zamienia się w wartość pustą, a także czasami jest całkowicie zerowy, ale to nigdy nie powinno się zdarzyć, ponieważ tylko autoryzowani użytkownicy mogą uzyskać dostęp do koncentratora.Context.User zmienia się na NULL w dziwny sposób na Signalr
Co jest przyczyną tych dziwnych zachowań? Używam SignalR 2.0 z ASP.NET MVC 4 na 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();
}
}
Czy jesteś pewien, że nie "czekasz" nigdzie pomiędzy tymi dwoma liniami? – SLaks
@SLaks Nie używam czekania w dowolnym miejscu kodu. – Freshblood
znalazłeś rozwiązanie? Mam do czynienia z tym samym problem. Mam znaleźć coś interesującego tutaj - http://forums.asp.net/t/1895487.aspx ale to nie pomaga mi –