title: SignalR inside _Layout.cshtml - persist connection
body: <p>I decided to use SignalR for chat on my page. Chat page is opened when user clicks on "Enter Chat" link which is placed inside _Layout.cshtml. This works fine. However, what I would like to achieve is the following functionality:</p>
  
  <ul>
  <li>On the left side of the page I would like to have some kind of
  "online users" area and when one user logins, other users whose are
  already logged in will be able to see that a new user just enters the
  page.   </li>
  <li>Users who are online can chat with each other by simply
  clicking on their names</li>
  </ul>
  
  <p>I am using the following code to connect to the chat application:</p>
  
  <pre><code>$(function () {
              //declare a proxy to reference the hub
              var chatHub = $.connection.chatHub;
              registerClientMethods(chatHub);
              //Start Hub
              $.connection.hub.start().done(function () {
                  registerEvents(chatHub);
                  chatHub.server.connect(@User.Identity.Name);
  
  
              });
          });
  </code></pre>
  
  <p>However when I place this code inside my _Layout.cshtml page, users are permanently logged off and connected again each time they navigate through pages (they are intended to be opened inside _Layout.cshtml). 
  Is there any way for persisting connection with the hub when navigating through page? What is the best practices when using this kind of functionality?</p>