Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Session State doesn't persist after postback (code: C#)

Reply
Thread Tools

Session State doesn't persist after postback (code: C#)

 
 
=?Utf-8?B?QWlkYXMgUGFzaWxpcw==?=
Guest
Posts: n/a
 
      09-15-2005
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.
 
Reply With Quote
 
 
 
 
zzzxtreme@yahoo.com
Guest
Posts: n/a
 
      09-15-2005
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)

 
Reply With Quote
 
 
 
 
=?Utf-8?B?QWlkYXMgUGFzaWxpcw==?=
Guest
Posts: n/a
 
      09-15-2005
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
 
Reply With Quote
 
=?Utf-8?B?c2VyZ2UgY2FsZGVyYXJh?=
Guest
Posts: n/a
 
      09-15-2005
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

 
Reply With Quote
 
Bruce Barker
Guest
Posts: n/a
 
      09-15-2005
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 http://www.velocityreviews.com/forums/(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
posting radiobuttons inside a gridview do not persist selection after postback.. Carlos ASP .Net 10 12-05-2006 04:36 PM
Unable to serialize the session state. Please note that non-serializable objects or MarshalByRef objects are not permitted when session state mode is 'StateServer' or 'SQLServer'. Mike Larkin ASP .Net 1 05-23-2005 12:33 PM
Cannot persist data after postback Grey ASP .Net 2 09-07-2004 09:14 PM
Does session cookie persist when after session times out? =?Utf-8?B?RWFybCBUZWlncm9i?= ASP .Net 2 07-28-2004 06:42 PM
unable to make the session state request to the session state server shamanthakamani ASP .Net 1 11-20-2003 04:51 AM



Advertisments