title: How to transfer context to a WebSocket session on reconnect?
body: <p>I am working on a web application in C#, ASP.NET, and .NET framework 4.5 with the use of WebSockets.  In order to plan for scalability in the future, the application pool has the option for web gardens enabled to simulate multiple web servers on my single development machine.</p>
  
  <p>The issue I am having is how to handle re-connects on the websocket side.  When a new websocket session is initially created, the client browser can indirectly lock records in a SQL database.  But when the connection is lost, my boss would like the browser to attempt to re-connect to the <em>same</em> instance of the websocket server session so it doesn't need to re-lock anything.</p>
  
  <p>I don't know if something like this is possible because on re-connect the load balancer will "randomly" select which web server to handle the new connection.  I was thinking of some hack to work around this but it isn't very clean:</p>
  
  <ol>
  <li>Client opens initial websocket connection on Server A and locks a record.</li>
  <li>Client temporarily loses internet connection and the websocket closes.  (It is important to note that the server side will wait up to 60 seconds before it "disposes" itself; therefore, the SQL record will remain locked until the 60 seconds has elapsed).</li>
  <li>Client internet connection is restored and reconnects to the website but this time on Server B.</li>
  <li>Server B sees that this context was initially connected on Server A; therefore, transfers the session to Server A.</li>
  <li>Server A checks the process id to see if it is running in the correct worker process (in the case of a web garden).</li>
  <li>Server A has found the initial instance and handles the connection.</li>
  </ol>
  
  <p>I tried Googling this question but it doesn't seem like a very common issue because I don't think most websocket web apps keep records locked for as long that my applications does (which is could be up to an hour).</p>
  
  <p>Thanks in advance for all of your help!</p>
  
  <p><strong>Update 3/15/2016</strong></p>
  
  <p>I was hoping that the <code>Server.TransferRequest</code> would have been helpful however it doesn't seem to work for web sockets.  Would anyone know of a way to best transfer a websocket context from one process to another?</p>