ASP/.NET Web Hosting
* 3 Months FREE *
CLICK HERE!
 CoverYourASP --> Using Session variables to maintain state --> Part 2

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
318 active users
1758 visitors today
2636 pages today
how is this done?
ASP.NET Showcase
ASP.NET Graph and Chart Component with FREE developer version

ASP.NET Shopping Cart and E-commerce Control with FREE trial download

ASP.NET Web Hosting with free month and setup

$15 Domain Name Registration from .DNR.
As seen on these sites
Special thanks go to the sites that support me by publishing my articles.
See more

CoverYourASP
Copyright © 1999-2008 James Shaw.
All rights reserved.

ASP.NET Blog
ASPRSS
ShawThing

Now open source with SourceForge!

Creating a new session

The first time a new user visits a page on your site a new session is automatically created. How? Well, in answering that we'll discover the major limitation of the Session object - it relies on cookies.

If you don't know already, cookies are simply data stored on your computer and automatically sent to the server by browsers when requesting a page. (Incidentally, they are perfectly safe. They can't collect personal information from your computer like some think. Read more about privacy and cookies.)

So the first time a user visits, there's no cookie and the server creates a new session and sets a cookie with a unique value. As the user browses your site the cookie is sent back and forth between your computer and the server, allowing the server to recognise the user.

To your ASP page it's a transparent process. In case you're interested, here's the actual cookie we're sending back and forth right now:

undefined

Unless you have cookies disabled, or are using a browser that doesn't support them, you should see something like ASPSESSIONID followed by a lot of gibberish. That's the unique value I was telling you about, and how the server recognises you as an earlier visitor.

Disabling sessions

If you don't want to track sessions (and if you're not storing any data in the Session object, you don't) disable them. Your server will appreciate it since it won't have the overhead of managing all those cookies. Add this line to the top of your pages:

<%@ EnableSessionState=False %>

Part 3: Tracking new sessions...

Featured sponsor
My favorite resources

Selling products online - read how James does it now


CoverYourASP Mugs, T-shirts, caps - even Boxer shorts...
I don't make a penny from these, but they're a lot of fun! Don't you need a new mouse mat?


I share my content

Supporting ASPRSS

Do you need a quick and easy way to link to my articles? All the information you need is published with ASPRSS...