473,320 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Session State in SQL Server

I have 2 web servers that are both hosting copies of my ASP.NET website that are both firewalled off from each other but can both see the same sql server database. The load balancing is handled by DNS therefore it is possible for a user to be changed from server 1 to server 2 during their session and this would cause a loss of session information.

I am therefore trying to get the session info storing on the sql server database instead, but I just can't get it to work.

I have setup the ASPState database using the aspnet_regsql.exe, and both servers seem to store their data to this database. But the problem is that they both seem to have their own sessions and don't share them.

I knocked up a demo page that stores some data to session then retrieves it from session. I can store the data and retrieve it on http://server1/sessionSharing/Default.aspx, if I then switch to http://server2/sessionSharing/Default.aspx and try to retrieve the data from session it blows up saying there isn't any.

After much googling it sounded like adding a machine key to my config would solve this problem but it doesn't make any difference. I've tried it in web.config and machine.config but still no good. I'm starting to wonder if I have missed something very fundamental here. Should I be setting some sort of cookie manually perhaps or does this happen automatically? My browser doesn't seem to be prompting me to accept or reject cookies on my demo site even though it does on other sites. Do I have to enable forms authentication or something? I noticed that the session ID that I am displaying on the page seems to change with each postback, is that right? It works OK if I put the session ID in the url but I don't like this solution as it causes problems with people bookmarking etc.

All I have done so far is as follows (keys have been redacted so may not work like this).
web.config
Expand|Select|Wrap|Line Numbers
  1. <sessionState mode="SQLServer" sqlConnectionString="Data Source=server1;User ID=test;Password=test"></sessionState>
  2. <machineKey validationKey="xxxxxxxxA5EC9214B0063AEFC8E0354998F393D81D1D3AD7551C792DF00ADA736B410E71C1791B70AE925AFE15BFB5FBF4EFAF2E4A55008FA06F31D8xxxxxxxx" decryptionKey="xxxxxxxx8DFA128AB16A1985C48F2491DBEF5744xxxxxxxx" validation="SHA1" />
  3. <authentication mode="Windows"/>
  4.  
Default.aspx.cs
Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)
  2.     {
  3.         Label2.Text = HttpContext.Current.Session.SessionID;
  4.         Label1.Text = ConfigurationManager.AppSettings["ServerName"];
  5.     }
  6.     protected void btnStore_Click(object sender, EventArgs e)
  7.     {
  8.         Session["Data"] = TextBox1.Text;
  9.     }
  10.     protected void btnRetrieve_Click(object sender, EventArgs e)
  11.     {
  12.         TextBox2.Text = Session["Data"].ToString();
  13.     }
Thanks in advance for any suggestions.

Ben.
Jul 20 '09 #1
0 1422

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Phil Grimpo | last post by:
I have a very odd situation here. I have an administration page, where based on a users permissions, a recordset is called from the SQL server which has a list of paths to "Module Menus". Each of...
3
by: Nhi Lam | last post by:
Hi, I understand that there are 3 modes in which I can configure the SessionStateModule. What I need is an out of process Session State store with fail over support. The "SQL Server Mode" seems...
2
by: John A Grandy | last post by:
for high traffic public websites , what are the proven options for session-state storage & management ? is an out-of-process state-server generally preferred over a sql-server ? what are the...
10
by: tshad | last post by:
I have been using the default session state (InProc) and have found that I have been loosing my information after a period of time (normally 20 minutes). Is there anyway to find out how much...
0
by: Maciek | last post by:
Hi When I set Session state mode to StateServer (IIS 6.0; windows2003; .NET 2.0) in my application, I have recived this message:...
9
by: McGeeky | last post by:
Is there a way to get a user control to remember its state across pages? I have a standard page layout I use with a header and footer as user controls. Each page uses the same layout by means of...
9
by: cashdeskmac | last post by:
I have put a string into Session and tried to retrieve it on the next page I visit but the Session appears empty. I have exactly the same spelling for both adding and retrieving the value: ...
2
by: DC | last post by:
Hi, we are using ASP.Net 1.1 on eight servers with one session state server (the windows 2003 service). Too often we are getting the exception "Unable to make the session state request to the...
14
by: GaryDean | last post by:
The web.config in my asp.net application, running on Server2003, has this entry: <sessionState mode="InProc" timeout="40". In IIS the asp.net State Management timeout setting is 40 for my website....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.