views:

112

answers:

2

I'm creating web application behind load balancer. To this moment I configured it to store session in database but I'm not sure how should I handle session expiration. The problem is not sessions are not removed from database but Session_End event because I have to call some web service method in it.

Assuming Session_End is called when expires the thing I'm afraid of is situation when session is created on one server but finished on another. In this case I'm afraid Session_End on first server will be executed prematurely and I will call web service too early. What would you suggest in this situation?

Edit:

I remember some time ago reading about Sql Agent reacting to session end event and then performing custom code. Can anybody confirm that this solution is possible?

A: 

Isn't this exactly why you are storing session information within a database?

This solves the problem of "which server is the session on."

As stated below Session_End is only called for inProc session, which you won't be using.

Jack Marchetti
Yes, but the thing I'm woried about is... for example (timeout=10min): User opens page on server A then after 9 minutes load balancer switches to server B. From reading documentation and blogs I understood that Session_End will be called after 10 minutes from session creation on server A and after 19min on server B because timeout timer is not aware of other server and that session was extended. Please correct me if I'm wrong.
Sergej Andrejev
+2  A: 

The session end event is not supported unless you are using in-process session state. You could look at ScaleOut Software StateServer. I am considering this for my own environment. It implements a distributed session state and support a session end event.

Edit to add more info:

Their web site explains it better that I can (details page), but here is a quick summary. ScaleOut (or similar gadgets) use a distributed cache to manage session state. This means that a process on each of your servers holds session data. The processes communicate between servers, so that all data is shared among all the servers - whichever server happens to be processing a user request, the same session data is available. If one of your servers fail, all session data is preserved, since it is distributed across all servers. In contrast, asp.net provides in-process session state which works only on a single server, a session state server which holds session data in a separate single server (a single point of failure), or sql server session state, which is quite robust, but hurts performance.

Ray
I doubt I could push this to management when project is so close to an end. For now I have only option and that is to use Sql Server.
Sergej Andrejev
If the issue is deployment delays, I believe that this product is pretty easy to install and configure, and requires few changes to your code (however, since I haven't installed it myself yet, I could be way off). If the issue is cost, well...
Ray
Anybody who whotes for this answer can explain benefits of ScaleOut?
Sergej Andrejev
@Sergej: edited to add more info
Ray