【发布时间】:2014-02-25 00:24:34
【问题描述】:
这让我发疯了。
我正在使用最新的 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();
}
这是我的Controller的登录方法:
[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 模板。
你知道出了什么问题吗?
【问题讨论】:
-
即使对于 SO 来说似乎也是一个棘手的问题...... SignalR 的所有者在哪里......我一直在阅读 2.0.3 版可能会在 OnDisconnected 时解决类似的问题,但是很长一段时间没有消息。像安全性这样对工作至关重要的东西不能正常工作。真倒霉。
-
由于某种原因,如果计算机时钟的时间不正确(例如一个月前),Context.User 将为空。
标签: asp.net-mvc authentication signalr signalr-hub owin