在SignalR中,我體驗到Context.User突然變爲空值,它有時也完全爲空,但這絕不應該發生,因爲只有授權用戶才能訪問集線器。Context.User在Signalr上更改爲null
這些奇怪行爲的原因是什麼?我上的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();
}
}
你確定你不是在等待這兩條線之間的任何地方嗎? – SLaks
@SLaks我不用在代碼中的任何地方等待。 – Freshblood
您是否找到了解決方案?我面臨同樣的問題。我在這裏找到了一些有趣的東西 - http://forums.asp.net/t/1895487.aspx但它不幫助我 –