How to loose session data in Web Farm ?

There are many things can cause session data lose but I came across very interesting scenario where session data intermittently get lost while storing
session data in SqlSessionStateStore. And after long troubleshooting found it was the App ID assigned to the same web application is different in the 2 servers in the web farm. Thus when request complete processing on
the 2nd server it consider as new one and assign new AppID.

SqlSessionStateStore scopes data by application, so that multiple applications can store sessions in one session state database. To that end, the session state database contains an ASPStateTempApplications table that records application names and application IDs. Application names are not explicitly specified as they are for other providers; instead, SqlSessionStateStore uses the website's IIS metabase path as the application name. Application IDs
are hashes generated from application names by the stored procedure GetHashCode. (SqlSessionStateStore differs in this respect, too, from other SQL providers, which use randomly generated GUIDs as application IDs.)

Ref https://msdn.microsoft.com/en-gb/library/aa478952.aspx>

Here is how can you reproduce the same:

 In Web Farm of 2 web servers for example But not in the same order so you may have different app id

 

 

 

Then when you check the ASPStateTempApplications table in ASPState DB you will find 2 different record for the same APP like:

 

 

 

 Hence when session gets created it is formed as Session ID + App ID. So if the APP ID is different its hashing would be different so it will generate 2 different
session IDs for the same user as in  the following example

 

o2f3t4crsssufg0ppenzvduv0e8cc1f9 = O2f3t4crsssufg0ppenzvduv (SessionID) + 0e8cc1f9 (APP ID)

o2f3t4crsssufg0ppenzvduv2476b033 =O2f3t4crsssufg0ppenzvduv (Session ID) + 2476b033 (APP ID)

 

 

 So make sure to make every single server in the farm identical.