Wife/Girlfriend/Sister?
Pepper Spray &
Stun Gun Specials!
KEEP THEM SAFE.
 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
55 active users
509 visitors today
1146 pages today
how is this done?
Tools I use

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

ASP.NET Blog
RSS submissions
E-commerce

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:

ASPSESSIONIDAQDQSSRR=CHPHJIOADHDINMOMBFLAPOAH

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

Tiki Statues - Tiki Masks - Tiki Totems



Qualify for Free Trade Magazines

Free subscriptions to industry leading publications for those who qualify!


See my source code
wherever you see this icon...

You can also download the entire site source code for FREE!