这让我疯狂。Context.User.Identity.Name在SignalR 2.X.X中为null。如何解决它?
我正在使用最新的signalR版本(2.0.2)。这是我的枢纽代码(OnConnected)
public override Task OnConnected()
{
//User is null then Identity and Name too.
Connections.Add(Context.User.Identity.Name, Context.ConnectionId);
return base.OnConnected();
}
这是我的控制器的登录方法:
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (ModelState.IsValid)
{
var user = await UnitOfWork.UserRepository.FindAsync(model.UserName, model.Password);
if (user != null)
{
await SignInAsync(user, model.RememberMe);
return RedirectToLocal(returnUrl);
}
}
TempData["ErrorMessage"] = Resources.InvalidUserNameOrPassword;
// If we got this far, something failed, redisplay form
return RedirectToAction("Index","Home");
}
我发现,一些人正在对OnDisconnected这个问题上,我甚至不让它有。
我正在使用MCV5模板。
你知道什么是错的吗?
好像连这么一个棘手的问题... SignalR所有者在哪里..我一直在阅读2.0.3版本,可能会在OnDisconnected时解决类似问题,但是很长一段时间没有消息。一些对安全工作至关重要的东西无法正常工作。不好运气。 – MRFerocius
由于某些原因,如果计算机时钟不在正确的时间(例如一个月后),Context.User将为空。 –