0

Possible Duplicate:
Passing session data between ASP.NET Applications

I created two web sites, website1 and website2

In both of these websites web.config have the below settings

<sessionState mode="SQLServer" sqlConnectionString="data source=localhost;user id=sa;password=<****>;"></sessionState>

In website1 default.aspx.cs, i have the below code

  Session["Test"] = "Test";
  Response.Redirect("http://localhost/WebSite2/default.aspx");

In website2 default.aspx.cs, i have the below code

Response.Write(Session["Test"]);

but am not able to retrieve the session stored

Community
  • 1
  • 1
Arun
  • 42
  • 1
  • 8
  • 3
    Session is "per-user/per-session (connection)" - you cannot retrieve one user's session in one app from another app. – marc_s Jun 15 '11 at 11:49
  • Already answered http://stackoverflow.com/questions/616046/passing-session-data-between-asp-net-applications – Otto Jun 15 '11 at 11:55
  • See also: http://stackoverflow.com/questions/623551/can-you-share-the-session-variables-between-two-net-2-0-applications/628972#628972 - ignore the downvote and the answer's first sentence. The rest is a good explanation. Also see Darin's answer below it. – Kev Oct 02 '11 at 12:29

1 Answers1

0

In the connection string example you attached you are storing the session locally on the web server; it wont get stored on both rather the first one the user logs into.

As i see it you have 3 options depending on your circumstances 1) You could use session aware load balancing to send users to server 1 or server 2 every time they connect or 2) Store the session on a single sql server and both web servers will be able to see the session data. 3) If that isn't practical for load ballancing or uptime reasons w0rite a service on each web server that checks the other one if it can't find the session details locally.

u07ch
  • 13,324
  • 5
  • 42
  • 48