views:

277

answers:

4

I have a need to maintain the session state in the database. However I cannot access the database directly from the web server. The web server communicates with an app server which in turn has access to the database.
Is there a way to configure this? Or does a custom component have to be written.
The reason for this setup is to allow for load balancing and to allow the session of a user to be redirected from one server to another.

+1  A: 

You can write a custom SessionState provider.. I think it's the only way.. Have a look on MSDN here.

Andrei Rinea
If I knew you had the option of using the StateServer I would have recommended it in the first place. It's faster than the SQL Server store and its only drawback is that it doesn't survive a physical reboot of its host machine. Which should not really be a problem usually.
Andrei Rinea
+2  A: 

Your only option is to build a custom component.

They really aren't that difficult to do as the only thing you need is for the browser to send you a value from either a cookie or the query string. What's stored is simply name value pairs.

see http://msdn.microsoft.com/en-us/library/aa479034.aspx

Chris Lively
+3  A: 

Note that if you think you need to store sessions in the database because you are using more than one web server, that is not the case: you can use StateServer. That means you enable the session state service on one machine and set up that machine in the web.config of all your web servers so that they all use the same machine for state.

RedFilter
Do you mean to say that I can have the App server configured to manage sessions as a "StateServer" ?
Nick
StateServer runs on SQL server which would require direct access to the database server...
Chris Lively
No Chris Lively, StateServer is a Windows Service that can run on ANY of the machines. It does not use a persistent store, it just stores them in RAM.
Andrei Rinea
@Nick - yes exactly. You can use one of your app servers, or a different server entirely, so that the memory used up by session handling does not affect your app.
RedFilter
see here: http://msdn.microsoft.com/en-us/library/ms972429.aspx and read the Out-of-process Mode section
RedFilter
+3  A: 

Use the ASP.NET Session State service, You can run this service directly on your app server - see notes on MSDN here - and configure all your web hosts to store their user session state on that central state server. The ASP.NET Session State service stores sessions in memory on the app server, and doesn't require a SQL Server database.

Dylan Beattie