Signalr InvalidOperationException

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

Exception Type: InvalidOperationException Exception Message: Unrecognized user identity. The user ID cannot change during an active SignalR connection.

Server stack trace: in Microsoft.AspNet.SignalR.PersistentConnection.GetConnectionId (HostContext context, String connectionToken) in Microsoft.AspNet.SignalR.PersistentConnection.ProcessRequest (HostContext context) in Microsoft.AspNet.SignalR.Owin.CallHandler.environment IDictionary 2 environment) at Microsoft.AspNet.SignalR.Owin.Handlers.HubDispatcherHandler.Invoke(IDictionary 2) in Microsoft.Owin.Host.SystemWeb.OwinCallContext.Execute () in Microsoft.Owin.Host.SystemWeb.OwinHttpHandler.BeginProcessRequtext ( httpContext, AsyncCallback callback, optional object data)

And in some cases, I have repeatedly received this error. And the event log is filled in a couple of minutes. I override the OnConnect, OnDisconnect functions in my hub class and initiated a hub connection with a Java script.

+4
source share
1 answer

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

It looks like your β€œother” browser should just be a different browser window. When you log into the application in another window, it changes your ASP.NET forms authentication cookie (and therefore your identifier) ​​in both browser windows.

Any current SignalR connections will be thrown into the above InvalidOperationException when they try to reconnect after changing the browser authorization cookie. SignalR may try to reconnect quite often if long polling is used. Once the recreation fails due to an exception, SignalR will try to reconnect for approximately 40 seconds , after which SignalR will fail and disconnect.

+3
source

Source: https://habr.com/ru/post/1480148/


All Articles