What can I do to use Session on a shared hosting server with load balancing

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!

Upvotes: 1

Views: 660

Answers (3)

slugster
slugster

Reputation: 49965

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.

Upvotes: 2

mikerobi
mikerobi

Reputation: 20878

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.

Upvotes: 0

Daniel Schaffer
Daniel Schaffer

Reputation: 57872

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.

Upvotes: 0

Related Questions