我正在使用SignalR 1和MVC4 C# Web应用程序,采用表单身份验证。我的布局页面中有JavaScript代码:
$(documnet).ready(function(){
connect to hub code ...
})
我想从服务器端的帐户控制器和方法中断开用户与中心的连接,并在其进行登录并验证通过后重新开始连接。
public ActionResult LogOn(LoginModel model, string returnUrl)
{
if (ModelState.IsValid)
{
if (System.Web.Security.Membership.ValidateUser(model.UserName, model.Password))
{
FormsAuthentication.SetAuthCookie(model.UserName, false);
....here , disconnect from hub
....to make the user reconnect
}
我想这样做的原因是因为如果用户在登录后更改为已验证状态而连接仍然存在,SignalR会抛出错误。这个错误是:
连接ID格式不正确。