views:

34

answers:

3

My website/application is in ASP.NET. I use the traditional Session object when people connect so they have their preference, etc.

My problem is that sessions were lost very often. I discovered that my hosting company was using load balancing on their servers, so one request on my website can be on one server, and the other on another one.

I tried to store the session data in a SQL Server database, but I quickly discovered that I can't create the needed database on my shared server because I only have one database in my package. Also, there is no guarantee that the rest of the script would have been able to run.

My questions: is there any other way to get around this problem? Should I buy another database only for this? Is there another type of session that I could use? Is there anything else I can use instead of session to keep track of my user when they are connected on my website?

I'm really open for any type of solution! Thanks a lot!

Jean-Francois

A: 

This sounds like a possible configuration with your hosting provider. Try contacting them and asking about it. They may need to configure something colloquially called "sticky sessions" at their load balancer.

That said, it seems very odd to me that load balancing would be used for a shared host client like this. I'd double check to make sure this is actually the case.

Daniel Schaffer
I already double checked... I will see if something is possible for the sticky session.
DarkJaff
A: 

You can manage your own sessions. You need to generate a random sessionId and store it in a cookie. You can use an existing table in your database. Just create your own class for reading and writing the session data based on the value in the cookie.

mikerobi
That's a good idea. Do you have a website with a tutorial on this so I can see the best way to do that?
DarkJaff
After analysing the problem and see if manage everything by myself was possible I discover that it is not a possibility. Session need's time out done by some job running. Everything is already done by the SQL Server session. It would be reinventing the wheel to try to program this again. I think that upgrading my package or changing company could be a better option. Thanks!
DarkJaff
+1  A: 

ASP.NET allows you to specify how you want the Session management handled.

As you've discovered you can use SqlServer mode - but this doesn't have to point to a separate database, it can use the same database that you already have.

There are also separate third party packages for managing web farm sessions, but you probably don't want the expense (and probably won't be able to install a package like this) for the setup you have.

slugster
I will try to modify my script to run everything on the same database. Thanks for pointing this. I hope it will work!
DarkJaff
The hosting company don't let me run everything in the script... There is some EXECUTE in the script with job, etc.. This is the script that is created by Framework.NET and that work perfectly on my machine... I ask them why I don't have the permission...
DarkJaff