iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

May 17, 2008
Learn HTML forms
About
 
May 16, 2008
Who Are Your Top Friends on Facebook?
About
 
May 15, 2008
Reader Question - Would you host your client's work on your website?
About
 
May 15, 2008
How to Create an Ajax Autocomplete Text Field: Part 6
WebReference.com
 
May 14, 2008
Poll: Are the browser safe colors still needed?
About
 
May 14, 2008
Google Doctype launched
About
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /ASP.NET

HOWTO: Make sessions really work in .NET 

  Views:    6338
  Votes:    5
by Hawkfield Tech 10/27/04 Rating: 

Synopsis:

You have sessions in every web based programming language. You have them in PHP, in ASP, and why would ASP.NET be any different. But ASP.NET has a better management of them, we explain how to take advantage.
Pages: 
The Article

Basically, a session is data that is kept over multiple requests for pages. A session was ussually stored on the server with a cookie, containing the session ID, on the client PC. ASP.NET is no different here, but there were several problems with this system.

First of all, the data would be stored on the server that made the request. If you happen to have multiple servers, serving the same user, the user had in fact 2 different sessions (one for each server). In ASP.NET, this can be solved in 2 ways. First of all you can store all the session information in an SQL server. 1 SQL server, serving multiple webservers, result in 1 session per user for all the servers. A second solution is the specifically designed StateServer. This server does nothing but keep track of user sessions (of course this can phisically be the same machine as one of the webservers).

A second problem was the cookie sent to the client PC. Not all browsers support cookies, or the client has them turned off. This can also be easily solved in ASP.NET. It's as simple as changing 1 value in your applications Web.config.

The section in the Web.config responsible for all this is the section.

Here is what is possible in it:

 mode="Off|InProc|StateServer|SQLServer"
cookieless="true|false"
timeout="# minutes"
stateConnectionString="tcpip=hostname:port"
sqlConnectionString="data source=hostname;user id=***;password=***" />

Mode
Off = No sessions
InProc = Standard, about the same as in ASP
StateServer = 1 server does the work
SQLServer = the database server does the work

Cookieless
Send a cookie to the client or incorporate the session ID into every request.
Setting this to true has serious consequences for your search engine placement, as they don't like session IDs in your URLs.

Timeout
The time in minutes after which a session expires when being idle.

StateConnectionString
How to connect to your StatServer, this will be ignored if the mode is not set to StateServer

SqlConnectionString
How to connect to your database server, this will be ignored if the mode is not set toSQLServer


Article by:

Hawkfield.Tech: Article based resource site
Hawkfield: Web design and development

Pages: 

Similar/related articles:


 
  Sponsors