473,378 Members | 1,330 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,378 software developers and data experts.

session object reinstantiated every time page is refreshed

I'm creating a basic page like the on below. Problem is evertime I
refresh the page or spawn a "child window" out of the pre-existing
browser the Session object is recreated with a new sessionID. Am I
doing something wrong? is it possible it could be the hosting company?
Any suggestion would help.

<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="test_Default" Culture="auto"
meta:resourcekey="PageResource1" UICulture="auto" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<% Response.Write(HttpContext.Current.Session.Session ID); %>
</div>
</form>
</body>
</html>

May 10 '06 #1
8 2168
Sessions usually rely on cookies; check your browser settings first.

If those look ok, then it could be the hosting company turns off
session by default, or your web.config is turning it off.

May 10 '06 #2
> I'm creating a basic page like the on below. Problem is evertime I
refresh the page or spawn a "child window" out of the pre-existing
browser the Session object is recreated with a new sessionID. Am I
doing something wrong? is it possible it could be the hosting company?
Any suggestion would help.

<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="test_Default" Culture="auto"
meta:resourcekey="PageResource1" UICulture="auto" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<% Response.Write(HttpContext.Current.Session.Session ID); %>
</div>
</form>
</body>
</html>

If this is the only page you use, there might be something else going
on:

The session is not stored on the server if there *is* nothing to be
stored! Try this page again, but also write something *to* the session.
Hans Kesting
May 11 '06 #3
Weird, it does seem to be the case that if nothings in the session, a
new session is created everytime.

That's not quite what I'd expect, since I think in Net 1.1 the session
lasted as long as the browser was open.

May 11 '06 #4
That's actually by design. For a new session id to be generated, the session
dictionary must be stained and at least one request must have completed
successfully. See
http://support.microsoft.com/default...b;en-us;555082

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------

"Andy" <aj*****@alum.rit.edu> wrote in message
news:11**********************@q12g2000cwa.googlegr oups.com...
Weird, it does seem to be the case that if nothings in the session, a
new session is created everytime.

That's not quite what I'd expect, since I think in Net 1.1 the session
lasted as long as the browser was open.

May 11 '06 #5
Actually that explains why Session end events don't sometimes seem to
fire. It doesn't explain why you have to put something into the
session for it to persist in a single browser session.

Nor does it make sense to require anything in the Session object; its
perfectly feasble to write a website which autentiates a user and
communicates with the database without ever storing anything in the
session object. Its trivially easy to do this.. you keep track of what
the user is doing via form or querystring parameters. I don't think
either of these require the use of Session at all.

Could you post a link explaining when sessions will stick around? I'm
almost certain that you'd keep your session cookie as long as the
browser was open, even if you were just browsing static pages. At
least thats the behavior I've known in ASP and ASP.net 1.1. Haven't
build any 2.0 pages yet.

May 11 '06 #6
> Weird, it does seem to be the case that if nothings in the session, a
new session is created everytime.

That's not quite what I'd expect, since I think in Net 1.1 the session
lasted as long as the browser was open.


No, the session will not "last as long as the browser is open". How
should the server know that the browser is closed?
Instead the session ends when explicitly requested, of (default)
20 minutes after the last request. Whether the browser is open or not.

If nothing was stored in the session, then you will only get a new
session-ID, not a complete session.

Hans Kesting
May 12 '06 #7
> No, the session will not "last as long as the browser is open". How
should the server know that the browser is closed?
What IIS used to do in the past was drop a session cookie on the users
machine. This session cookie is a special type of cookie which
browsers know to remove once the window is closed. Thats what used to
happen in the past.
Instead the session ends when explicitly requested, of (default)
20 minutes after the last request. Whether the browser is open or not.
When the browser was closed, it would 'forget' the cookie. On the
server the session would exist until it timed out. Re-opening the
browser and sending a request to the site could cause another session
cookie to be dropped (because IIS didn't detect the existance of one).
If nothing was stored in the session, then you will only get a new
session-ID, not a complete session.


I'm pretty sure this is new behavior in .Net 2.0, as I don't think it
was the case previously. I haven't been doing as much web work lately
(mostly WinForms, but I am currently building a site), but it wasn't
long ago that web was the only kind of app I was building; I spent 7
years doing web work exclusively.

Andy

May 12 '06 #8
Andy was coorect. The Session does need to be stained; assigned with a
variasble in order for the Session Object to persist. Ofcourse IMO
thats straying away from the orignal purpose of a the Session Object.

May 16 '06 #9

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

Similar topics

3
by: Michelle | last post by:
Hi all, I am trying to store data in a $_SESSION variable (an array), but it reverts to empty every time my page is refreshed (due to a submit button click). I read the answer to the post...
27
by: mrbog | last post by:
Tell me if my assertion is wrong here: The only way to prevent session hijacking is to NEVER store authentication information (such as name/password) in the session. Well, to never authenticate...
4
by: Dica | last post by:
we've just set up a subdomain, 'demos' for one of our projects that normally works fine. on the login page, if the user enters the correct username/pw, we write session info and then...
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: William LaMartin | last post by:
I have a problem, mentioned here before, of Session and Application variables disappearing at one site but not at others or on my development computer. The problem is illustrated by an example...
2
by: Todd | last post by:
Here's one that has been stumping people: I'm writing in ASPX with VB.NET On the login page I set the entered usename text to a session variable....
4
by: N. Demos | last post by:
Hello, I'm learning ASP.NET, and am having a strange problem with some example code from the book I'm using. The code increments and displays the value stored in a session variable when the "Add"...
17
by: jensen bredal | last post by:
Hello, i'm struggling with a somehow badly understood session scenario. I provide acces to my pages based on form authentication using Session cookies. Som of my pages are supposed to be...
7
by: Mr Newbie | last post by:
I have written a Custom Control Menu. Its fairly simple but it works well enough. In order to simplify things I decided to store the Menu1 custom control in Session. In the page load event below,...
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...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.