473,320 Members | 1,881 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 doesn't persist after postback (code: C#)

I'm saving some values to the Session state and get some strange results.

To be short I'll write example code and standart behavior:

Code Example:
/////////////////////////////////////////////////////////////////////////////////////////

private void WriteToSessionButton_Click(object sender, , System.EventArgs e)
{
Session["something"] = "My value";
}
private void CheckSessionButton_Click(object sender, , System.EventArgs e)
{
if(Session["something"] != null)
{
SessionVariable_Label.Text = Session["something"].ToString();
}
else
{
SessionVariable_Label.Text = "N/A";
}
SessionId_Label.Text = Session.SessionID;
}

/////////////////////////////////////////////////////////////////////////////////////////
TYPICAL (CORRECT) BEHAVIOUR:

When I run my ASP.NET procejt from localhost
(http://localhost/MySessionProject/Default.aspx) after clreating required
Session variable by clicking the WriteToSessionButton button, I check Session
variables by clicking CheckSessionButton button.
The values are correct and after each Post_Back, no matter how many times I
click the buttons everything works just like it's suppost to be. I get the
Session["something"] value and same SessionId after each Post_Back.

THE PROBLEM:

However, when I open my project substituting "localhost" with My computer
name like this http://MyComputerName/MySessionProject/Default.aspx, after
creating Session variable and clicking CheckSessionButton button I get empty
variable (SessionVariable_Label.Text = "N/A") and the Session.SessionId value
is different after each Post_Back.

This behaviour is not random. It happens every time.

localhost - Session variable and SessionId remains;
MyComputerName - Session variable dissapears, Session.SessionId changes
after each Post_Back.

ABOUT SESSION STATE:
I tried InProc and StateServer configurations.

OTHER INFO:
And it's not page or project specific. It happens with any page or project.

It's also not machine (computer) specific as I tried it other development
computer in our network and got the same results.

I have Intel Pentium 2.8 DualCore CPU on both developement machines.

Network managed by ActiveDirectory.
Nov 19 '05 #1
4 15111
i had same problem with session not persisting
after tireless research, i gave up on windows2003 troubleshooting, and
just switch to sql server session
( i think MSDE works too)

Nov 19 '05 #2
Thank you for your reply, but I forgot to mention that I'm using Windows XP
Professional. And I had never experienced such problems before with windows
XP and Windows 2000.

I guess maybe it has something to do with DualCore processors. However at my
previous job we had App server with 4 cpus and there were no problems with
Session state.

Any way, thank you one more time.

If any one else has some other sugestions or thoughts, you're welcome to
post :)
Nov 19 '05 #3
hi,

I just test your sample code, just for beeing curious.
I did not face that problem, iot works fine

"Aidas Pasilis" wrote:
Thank you for your reply, but I forgot to mention that I'm using Windows XP
Professional. And I had never experienced such problems before with windows
XP and Windows 2000.

I guess maybe it has something to do with DualCore processors. However at my
previous job we had App server with 4 cpus and there were no problems with
Session state.

Any way, thank you one more time.

If any one else has some other sugestions or thoughts, you're welcome to
post :)

Nov 19 '05 #4
this is expected behavior with cookie based sessions. the session id is
store in a cookie, and sent by the browser on each request or post. session
cookies are tied to the domain and site.

to the browser

http://myservername/mysite
http://localhost//mysite
http://myipaddress/mysite

are three different servers and cookies and thus sessions are not shared
between them. you can switch to cookieless sessions to get around this (the
session id is added to the url, so changing servername has no effect).

-- bruce (sqlwork.com)


"Aidas Pasilis" <Aidas Pa*****@discussions.microsoft.com> wrote in message
news:E5**********************************@microsof t.com...
I'm saving some values to the Session state and get some strange results.

To be short I'll write example code and standart behavior:

Code Example:
/////////////////////////////////////////////////////////////////////////////////////////

private void WriteToSessionButton_Click(object sender, , System.EventArgs
e)
{
Session["something"] = "My value";
}
private void CheckSessionButton_Click(object sender, , System.EventArgs e)
{
if(Session["something"] != null)
{
SessionVariable_Label.Text = Session["something"].ToString();
}
else
{
SessionVariable_Label.Text = "N/A";
}
SessionId_Label.Text = Session.SessionID;
}

/////////////////////////////////////////////////////////////////////////////////////////
TYPICAL (CORRECT) BEHAVIOUR:

When I run my ASP.NET procejt from localhost
(http://localhost/MySessionProject/Default.aspx) after clreating required
Session variable by clicking the WriteToSessionButton button, I check
Session
variables by clicking CheckSessionButton button.
The values are correct and after each Post_Back, no matter how many times
I
click the buttons everything works just like it's suppost to be. I get the
Session["something"] value and same SessionId after each Post_Back.

THE PROBLEM:

However, when I open my project substituting "localhost" with My computer
name like this http://MyComputerName/MySessionProject/Default.aspx, after
creating Session variable and clicking CheckSessionButton button I get
empty
variable (SessionVariable_Label.Text = "N/A") and the Session.SessionId
value
is different after each Post_Back.

This behaviour is not random. It happens every time.

localhost - Session variable and SessionId remains;
MyComputerName - Session variable dissapears, Session.SessionId changes
after each Post_Back.

ABOUT SESSION STATE:
I tried InProc and StateServer configurations.

OTHER INFO:
And it's not page or project specific. It happens with any page or
project.

It's also not machine (computer) specific as I tried it other development
computer in our network and got the same results.

I have Intel Pentium 2.8 DualCore CPU on both developement machines.

Network managed by ActiveDirectory.

Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Ilia | last post by:
Hi folks, I have some problems with ASP.NET Session State. The following simple program runs well if the Session State set as "InProc". If I switch to "SQLServer", the changes, made by the...
9
by: Greg Linwood | last post by:
I'm having difficulty understanding Session state in ASP.Net. It's almost embarrassing asking this as I've been using ASP since it was first released & it really shouldn't be this hard to use -...
0
by: Michael O'Brien | last post by:
I'm trying to hook in a specialized state store server into ASP.NET. I understand I can create a HttpModule and hook the events OnAcquireState and OnReleaseState. So far so good. But, it seems...
3
by: moondaddy | last post by:
I'm writing a shopping cart in vb.net and for the first time I'm working with session state on the server. I'm using it to maintain the user's shopping cart for the session. in the browser is a...
3
by: grooby | last post by:
I would like to develop an asp.net Web application using muliple web projects under one solution file and share the session information between web applications( or projects). Is this possible?
3
by: Mark | last post by:
Ok, I know that .net inherently does not share session data across asp.net projects, but is there any decent work around to this. We already have a big chunk of our application using the asp.net...
0
by: Ian | last post by:
Hi there, A little confused about postback and sessionstate Does a postback use a session state by default? if so by default is this stored in a cookie? I was a little confused here, I have...
0
by: Nabani Silva | last post by:
Hi, hope someone could help I need to share session state (and contents) through differente web applications. I'm trying to get it done by using StateServer session state, below I paste code...
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.