4

I recently started using Signal R library in ASP.Net MVC 3 application. I am able to use Signal R to send message to client. But I noticed that if I logged in to the application from another browser, I get following error -

Exception type: InvalidOperationException Exception message: Unrecognized user identity. The user identity cannot change during an active SignalR connection.

Server stack trace: at Microsoft.AspNet.SignalR.PersistentConnection.GetConnectionId(HostContext context, String connectionToken) at Microsoft.AspNet.SignalR.PersistentConnection.ProcessRequest(HostContext context) at Microsoft.AspNet.SignalR.Owin.CallHandler.Invoke(IDictionary2 environment) at Microsoft.AspNet.SignalR.Owin.Handlers.HubDispatcherHandler.Invoke(IDictionary2 environment) at Microsoft.Owin.Host.SystemWeb.OwinCallContext.Execute() at Microsoft.Owin.Host.SystemWeb.OwinHttpHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object extraData)

And in some instances, I started getting this error repeatedly. And event log get full in couple of minutes. I override OnConnect, OnDisconnect functions in my hub class and initiated hub connection from the Java script.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
user2370912
  • 41
  • 1
  • 2

1 Answers1

3

SignalR does not allow a user's Identity to change while maintaining a connection. This is because SignalR's connectionToken acts as an anti-xsrf token.

It appears that your "other" browser must actually be just another browser window. When you log in to the application in another window, it changes your ASP.NET forms authentication cookie (and therefore your Identity) in both browser windows.

Any ongoing SignalR connections will run into the aforementioned InvalidOperationException when they attempt to reconnect after the browser's auth cookie has changed. SignalR may attempt to reconnect quite frequently if the long polling transport is being used. Once the reconnect fails due to the exception, SignalR will repeatedly try to reconnect for about 40 seconds after which SignalR will give up and disconnect.

Leniel Maccaferri
  • 100,159
  • 46
  • 371
  • 480
halter73
  • 15,059
  • 3
  • 49
  • 60
  • 1
    Any advice on the best way to solve this so that the connection is re-established in the old window but with the new identity? – chrisb Aug 23 '13 at 05:07
  • After a user's identity changes, you will to manually stop and restart the signalr connection. – halter73 Aug 27 '13 at 18:38