What is Cookie? What is the function of cookie?

Source: Internet
Author: User

Cookie is a Web applicationProgramIt provides a useful method to save user information. For example, when a user accesses your site, you can use cookies to save user preferences or other information, so that when the user visits your site next time, the application can retrieve previously saved information.

This article describes the application of cookies in ASP. NET applications. It shows you the technical details of cookie application in ASP. NET, such as compiling cookies and then reading them. In addition, we will introduce you to various features and special circumstances of cookies, as well as ASP. NET's support for cookies.

What is Cookie?

Cookie is a short text message that is transmitted between the Web server and the browser as user requests and pages. Each time a user accesses a site, the Web application can read the information contained in the cookie.

Assume that when a user requests access to a page on your website's http://www.contoso.com/, your application sends to the user not only a page, but also a cookie containing the date and time. The user's browser obtains the cookie while obtaining the page, and saves it in a folder on the user's hard disk.

Later, if the user visits the page on your site again, when the user enters the URL http://www.contoso.com/, the browser will find the cookie associated with the URL on the local hard disk. If the cookie exists, the browser sends it along with the page request to your site, and your application can determine the date and time of the user's last visit to the site. You can send a message to the user based on this information, or check the expiration time or perform other useful functions.

Cookie is associated with a web site rather than a specific page, so no matter which page the user requests to browse the site, the browser and server will exchange cookie information for the http://www.contoso.com. When a user accesses other sites, each site may send a cookie to the user's browser, and the browser will save all these cookies separately.

These are the basic operating principles of cookies. So what are the functions of cookies? The most fundamental purpose is that cookies can help websites save information about visitors. To put it more simply, cookie is a way to maintain the continuity of Web applications (that is, to execute "state management. The browser and the Web server are always disconnected except for a short period of actual information exchange, and each request sent by the user to the Web server is processed independently, regardless of all other requests. However, in most cases, it is necessary for the Web server to identify you when you request a page. For example, a Web server on a shopping site tracks each shopper so that the site can manage shopping cart and other user-related information. Therefore, the cookie function is similar to a business card. It provides the relevant identification information to help the application determine how to proceed.

Cookie can be used for multiple purposes, all of which are to make the web site remember you. For example, a site that implements a public opinion test can simply use cookies as a Boolean value to indicate whether your browser has participated in the vote, thus avoiding repeated voting; websites that require user login can use cookies to determine whether you have logged on, so that you do not have to enter creden。 every time.

The concept of cookie programming for ASP. NET Applications must be mastered. If you want to obtain JavaScript cookie programming, you can read this siteArticle:

<Javascript: Cookie details, instances, and Applications>

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.