954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

ASP.Net Session Variables in SQL

Hi

We have two identical web servers in a farm and I need them to be able to share Session variables as I do not know which machine the user will be using at any given time i.e. if a user where to log in to a site on server1 and then post back I cannot 100% guarentee that server 1 will process the request.

I have been looking at sharing session state through SQL but rather than do this on our live servers I set up a pair of VM's on my local machine to test. I have SQL (2005 Developer edition) installed locally on my machine so I decided to use this as my test DB.

On each machine, I posted up a test web site with a default page to enter some text (firstname and lastname) and then store these in a class which I have marked as serializable and store this class in a session variable.

On the Web config of the site(s), I have carried out the following:Set a common Machine Key to allow session state to be shared accross both servers
set enableViewStateMac to false
Set Session State mode to SQLServer
Added a SQL connection string to my local DB with a specified SQL login
Set Cookieless to use cookies
<machineKey validationKey="#######################" decryptionKey ="~~~~~~~~~~~" validation="SHA1" decryption="AES" />
<enableViewStateMac ="false" />
<sessionState mode="SQLServer" sqlConnectionString="server=<myServer>;uid=<SQLUser>;pwd=<Password>" cookieless="UseCookies" timeout="20" />


I ran the ASPNet_Regsql.exe on My database server with the -ssadd switch and the -t switch under my local user account -E

I then gave the user I'm using to connect to the Database execute permission on all the Stored proceudres in the ASPState Database and also INSERT, SELECT, UPDATE and DELETE permission on the tables set up in the tempdb database.

Finally on each of the local servers, I edited the IIS metabase to ensure both sites were on the same local path LM/W3SVC/################# and restarted the IIS service.

When I connect on the site on Server 1, I enter my details and submit this goes through to the next page and shows me the session variable details. - no issue

I then change the IP in the Url of my browser to that of the other server and open but when I get that page open the session variable has gone. If I switch back to the first server (again just mod the IP address in the browser link) everything is there.

Any one know what I'm missing?

G_Waddell
Posting Whiz in Training
255 posts since Nov 2009
Reputation Points: 43
Solved Threads: 27
 

Anyone??

G_Waddell
Posting Whiz in Training
255 posts since Nov 2009
Reputation Points: 43
Solved Threads: 27
 

No idea..I think just search on Google with machine.config file.
I think it is related to that

vikramrandhawa
Newbie Poster
8 posts since Aug 2011
Reputation Points: 7
Solved Threads: 2
 

No idea..I think just search on Google with machine.config file.
I think it is related to that

vikramrandhawa
Newbie Poster
8 posts since Aug 2011
Reputation Points: 7
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: