O'Reilly logo

Special Edition Using® Microsoft® ASP.NET by Richard Leinecker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Application and Session Variables

Application and session variables work similarly, each having a dictionary of objects. Keys identify each object in the dictionary. The keys are normally text strings that give a name to each object in the dictionary. For example, I might have a user ID object and I might name it UserId. The following simple example shows how an integer value of 12 could be stored in a session variable named UserId:

// C# 
Session[“UserId”] = 12; 

' VB 
Session(“UserId”) = 12 

It is just as easy to set a session variable to contain a string. The following examples show how to set session variables in C# and VB to a string containing the name John Doe:

 // C# Session[“UserName”] = “John Doe”; ' VB Session(“UserName”) = “John ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required