Monday, January 31, 2011

Different States in ASP.NET

An ASP.NET application ends after generating a web page. The current status of date maintained by the application is lost. In other words, HTTP does not maintain the state of the application. This is described in the below figure.

You can see that a browser on the client side requests a page from the web server. After processing the request and returning the page, the server drops the connection. Then. if the browser makes another request the server has no way to associate the browser with the previous request. So HTTP is called as a stateless protocol. But ASP.NET provides several ways to maintain the state.

View State
View state is used to maintain the values of server control properties. AS ASP.NET implements view state by default you need not to write any special code to use it.

Session State
Session state is used to maintain data between execution of an application. For this, ASP.NET creates a session state object that is kept on the server whenever a user starts a new session. The session state object contain unique session ID, and this ID is sent back and forth between the server and browser each time the user request a page. Then when the server receives a new request from the user, it can retrive the right session state object for that user. You can add data items to the session object in your code, so there previous values are available each time a web form is executed.

Application State

ASP.NET provides an application state object to save application state data, which applies to all the users of an application. You can use application state object to manage global counters to maintain a list of users who are currently logged on to an application.

Profile
ASP.NET also provides profile feature to keep track of user data. Although a profile is similar to session state object, it persists between user session as it is stored in a database. For example we can use profiles we can keep track of the products ordered by an user in an shopping application and when the user starts a new session, you can display those products in a "ordered items" listbox.

No comments:

Post a Comment

Ajax CalendarExtender displaying at wrong position in Chrome

< script type ="text/javascript" language ="javascript">     function onCalendarShown(sender, args)...