O'Reilly logo

ASP.NET 4 24-Hour Trainer by Toi B. Wright

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

Chapter 4. State Management in ASP.NET 4

As I mentioned in the Welcome, the Internet uses the Hypertext Transfer Protocol (HTTP) to enable browsers and web servers to communicate with each other. The problem with HTTP is that it is an inherently stateless protocol. This means that every page request is unrelated to every other page request. If you are building a web application that does more than display static data, you need to be able to associate data with a particular user over multiple page requests. Therefore, your web application requires state management.

In this lesson I show you how the ASP.NET framework is able to overcome the stateless nature of HTTP and simulate state. I also show you a few methods that the ASP.NET framework provides for storing data about a particular user.

SESSION ID

ASP.NET simulates state by assigning each user a randomly generated Session ID and sending that Session ID to the user's browser via a cookie. A cookie is a very small text file stored on a user's computer by a web browser. The browser sends the cookie back to the web site with any subsequent requests. In this manner, your web site is able to recognize returning users.

By default, ASP.NET stores the Session ID for each session in a cookie on the browser. The Session ID is generated by a random number generator that returns a sequence of randomly generated numbers that are mapped to valid URL characters and returned as a 120-bit string. This is the code to view the Session ID for the current ...

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