The difference between application,session and cookies

Source: Internet
Author: User

Method

Information size

Save time

Application scope

Save location

Application

Any size

Lifetime of the entire application

All Users

Server-side

Session

Small, simple data

User activity time + a delay time (typically 20 minutes)

Individual users

Server-side

Cookies

Small, simple data

Can be set as required

Individual users

Client

The 1.Application object application is used to hold public data information for all users, and if you use application objects, one of the issues to consider is that any write operations are in the Application_OnStart event ( Global.asax). Although the Application.Lock and Applicaiton.unlock methods were used to avoid synchronization of the write operation, it serialized the request for the Application object, Serious performance bottlenecks occur when the site is heavily visited. It is therefore best not to save large data collections with this object

The 2.Session object session is used to hold private information for each user. Her lifetime is the user's persistent request time plus a period of time (typically 20 minutes or so). The information in the session is saved in the Web server content, and the amount of data saved can be large or small. The saved data information is automatically freed when the session expires or is closed. Because the user stops using the application, it remains in memory for a period of time, Therefore, using the session object makes it very inefficient to save user data. For small amounts of data, it is a good idea to use session objects to save. The code for saving information using the Session object is as follows:

//Store information session[username< Span style= "color: #000000;" > "]=" zhouhuan "// read data string username< Span style= "color: #000000;" >=session[username< Span style= "color: #000000;" > "". ToString ();

3.Cookie Object cookie is used to save the request information of client browser Request Server page, the programmer can also use it to store non-sensitive user information, the time of saving information can be set as needed. If the cookie expiration date is not set, They are only saved until the browser program is closed. If you set the Expires property of a cookie object to MinValue, the cookie will never expire. Cookies are limited in the amount of data stored, and most browsers support a maximum capacity of 4096. So don't use it to save datasets and lots of other data. Because not all browsers support cookies, and the data information is stored in clear text in the client computer, it is best not to save sensitive, unencrypted data, Doing so will affect the security of your site. The code saved with the cookie object is as follows:

//Store information response.cookies[ Userid "". Value=0001 "; // read information string Userid=response.cookies[ Userid "". Value

Differences between application,session and cookies

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.