473,569 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 WriteToSessionB utton_Click(obj ect sender, , System.EventArg s e)
{
Session["something"] = "My value";
}
private void CheckSessionBut ton_Click(objec t sender, , System.EventArg s e)
{
if(Session["something"] != null)
{
SessionVariable _Label.Text = Session["something"].ToString();
}
else
{
SessionVariable _Label.Text = "N/A";
}
SessionId_Label .Text = Session.Session ID;
}

/////////////////////////////////////////////////////////////////////////////////////////
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 WriteToSessionB utton button, I check Session
variables by clicking CheckSessionBut ton 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 CheckSessionBut ton button I get empty
variable (SessionVariabl e_Label.Text = "N/A") and the Session.Session Id 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.Session Id 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 15173
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*****@discuss ions.microsoft. com> wrote in message
news:E5******** *************** ***********@mic rosoft.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 WriteToSessionB utton_Click(obj ect sender, , System.EventArg s
e)
{
Session["something"] = "My value";
}
private void CheckSessionBut ton_Click(objec t sender, , System.EventArg s e)
{
if(Session["something"] != null)
{
SessionVariable _Label.Text = Session["something"].ToString();
}
else
{
SessionVariable _Label.Text = "N/A";
}
SessionId_Label .Text = Session.Session ID;
}

/////////////////////////////////////////////////////////////////////////////////////////
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 WriteToSessionB utton button, I check
Session
variables by clicking CheckSessionBut ton 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 CheckSessionBut ton button I get
empty
variable (SessionVariabl e_Label.Text = "N/A") and the Session.Session Id
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.Session Id 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
5419
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 second thread, are lost. Any idea? I use VS.NET 2003 on Windows Server 2003 with hot fixes (as of 30-Oct-2003) and SQL Server 2000 SP 3a.
9
2370
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 - perhaps I'm just not very smart or perhaps MS is making this too hard for us sql bunnies to understand - I dunno, but I'd really appreciate someone...
0
1315
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 that the framework owns the HttpSessionState instance (HttpContext.Session) and so my state store module must use the Add, Remove and Clear methods...
3
1550
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 datagrid with a listing of products. If I put a break point in the code behind the code execution will break at that point just as you would expect....
3
1992
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
3433
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 session object (using state service). I'd like to start breaking out our functionality into component projects, but I'd like to get this session...
0
928
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 found out how to use the URL to stored the session state and how to remove session state completely.
0
1627
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 for web.config. Both applications are on the same server (I don't want to include all applications into one common virtual directory or application)
10
3489
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 more time I have on a session? If I do a refresh, does reset the session clock? Do you have have to go to another page to reset the session timeout...
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6287
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3657
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.