disconnect client from server side signalr

后端 未结 6 1324
梦如初夏
梦如初夏 2021-02-19 06:39

I\'m using SignalR 1 with MVC4 C# web application with form authentication. I have a code in my layout page in JavaScript :

$(documnet).ready(function(){
               


        
6条回答
  •  被撕碎了的回忆
    2021-02-19 07:20

    Try controlling everything from javascript. The following is a logout example, login would be similar.

    From http://www.asp.net/signalr/overview/security/introduction-to-security:

    If a user's authentication status changes while an active connection exists, the user will receive an error that states, "The user identity cannot change during an active SignalR connection." In that case, your application should re-connect to the server to make sure the connection id and username are coordinated. For example, if your application allows the user to log out while an active connection exists, the username for the connection will no longer match the name that is passed in for the next request. You will want to stop the connection before the user logs out, and then restart it.

    However, it is important to note that most applications will not need to manually stop and start the connection. If your application redirects users to a separate page after logging out, such as the default behavior in a Web Forms application or MVC application, or refreshes the current page after logging out, the active connection is automatically disconnected and does not require any additional action.

    The following example shows how to stop and start a connection when the user status has changed.

    
    
                                     
                  
提交回复
热议问题