Serving Information Simply

Monday, 15 October 2012

Difference between Application, Session, View State, Cookies & Query String.

I am introducing the main difference between Application, Session, View State, and Cookies & Query String.


The Application Object: The Application object stores data that is shared across the application and not for a specific user. Whereas every page request gets its own Request and Response objects, all requests for ASP pages in a Web application share the same Application object. This object is created the first time an ASP page is requested from the application after the Web server starts up, and is destroyed when the Web server shuts down, or when the Web application is unloaded manually in the IIS management console. Because this object persists from one page request to another, it can be used to store data that you want to share with all other pages in your application.
Syntax: Application(“varName”) = value
 
The Session Object: The Session object is very similar to the Application object, as it allows you to store values that are shared between all the pages of your site. The main difference between the two is that,     where a single Application object is shared by all pages and all clients that access your site, each client (browser) is assigned its own Session object. Thus, a Session object must be created for each user session that occurs on your Website.
Syntax: Session(“username”) = “Abhinav bajpai”

The View State: The ViewState allows ASP.NET to repopulate form fields on each postback to the server, making sure that a form is not automatically cleared when the user hits the submit button. All this happens automatically, unless you turn it off, but you can actually use the ViewState for your own purposes as well. Please keep in mind though, that while cookies and sessions can be accessed from all your pages on your website, ViewState values are not carried between pages. StateBag implements the view state and manages the information that ASP.NET pages and embedded controls persist across successive posts of the same page instance.
Syntax: ViewState(“FontSize”) = value

Cookie: Cookie is one of several ways to store data about web site visitors during the time when web server and browser are not connected. Common use of cookies is to remember users between visits. Practically, cookie is a small text file sent by web server and saved by web browser on client machine.
Syntax: Response.Cookies["MyCookieName"].Value=“MyCookieValue”;

Querystring: Query string is used to pass the values or information form one page to another page.
Syntax: Request.QueryString(variable)[(index)|.Count]

Thank you ! keep visiting guys....

5 comments:

  1. Hello abhinav

    very good post about difference between these. thanks

    ReplyDelete
  2. good difference

    ReplyDelete
  3. It is really a great work and the way in which u r sharing the knowledge is excellent.Thanks for helping me to understand basic concepts. As a beginner in Dot Net programming your post help me a lot.Thanks for your informative article. Dot Net Training in chennai | Dot Net Training in velachery

    ReplyDelete
  4. Given so much information in it. its very useful .perfect explanation about Dot net framework.Thanks for your valuable information. dot net training in velachery | dot net training in chennai

    ReplyDelete