Question

We have Windows Server 2008 R2 with IIS on in a web farm environment. I initiate a Classic ASP session and every so often, when refreshing the page, it doesn't show but then comes back again.

I go to http://mainurl.com but have two boxes called http://devbox1.com and http://devbox2.com

I put the files onto one of the DEV boxes which replicates to the other one.

After some reading, I guess this is down to a "common" issue with sharing sessions across a web farm instance.

Could someone please help me how to resolve this please?

Was it helpful?

Solution

Update:

As it's not clear in my post. Do not use the Session.SessionID as the identifier for the cookie as this will change across environments (Microsoft recommend never to store the SessionID in a database).

Quote from MSDN Library - Session.SessionID

You should not use the SessionID property to generate primary key values for a database application. This is because if the Web server is restarted, some SessionID values may be the same as those generated before the server was stopped. Instead, you should use an auto-increment column data type, such as IDENTITY with Microsoft® SQL Server™ or COUNTER with Microsoft Access.

Instead use a self generated id value that you then store in your cookie and the database. This way your Session object can be re-created.


There seems to be some discussion about solution using a database. Just to clarify Classic ASP uses Session object stored in memory this means the minute you switch machines load balanced or otherwise you still lose the session.

Interesting article on the IIS.net forums about this topic - iis 7 Load balancing

Quote from Bill Staples (who at the time was Product Unit Manager, IIS)

One thing to consider, however, is what to do with any application / session state. Classic ASP stores session state in memory that only one process can access. As soon as you scale the sites onto more than one machine, you can no longer guarantee that each incoming request for a particular user session is landing on the same machine, which means the client may suddenly 'lose state' between requests. This is why we recommend that you not use the built-in session support in ASP for these kinds of scenario. Instead we recommend you use SQL or another database to store this kind of data.

My recommendation would be to store the Session in a database create a cookie on the client machine then use this cookie to identify the session from the database.

Cookies can be changed so I would still recommend you use secure cookies across an SSL secured website, especially if data is of a sensitive nature.

OTHER TIPS

You should create sticky sessions while working with web farms because most likely you have load balanced system which under standard configuration will point traffic to the lowest loaded node. As result your users will loose session from time to time.

Ask your network admin team to look how to create sticky session for your particular load balancers and network configuration, they should know exactly what this means.Here is one of the examples what this is and how to configure it: http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/US_StickySessions.html. But once again it is depend on what you are using.

**** solution with cookies or database entries not the best way to handle this situation because once again depend on your web farm configuration IIS may simple reject any attempt to overwrite session ID which you have stored in database or if security is tight enough even refuse to connect to page while connecting to other node.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top