Asp. Basic knowledge of cookie programming in net (1)

Source: Internet
Author: User
Tags date
Introduction to|cookie| Programming

Cookies provide a useful way for a WEB application to save user-related information. For example, when a user visits your site, you can use cookies to save user preferences or other information so that the application can retrieve previously saved information the next time the user visits your site.

This article outlines the application of cookies in applications, showing you the technical details of applying cookies in, such as writing cookies and then reading them. You will also be presented with a variety of features and special circumstances for cookies, as well as support for cookies.

What is a Cookie?

A Cookie is a small piece of textual information that accompanies the user request and the page is passed between the WEB server and the browser. Each time a user accesses a site, the WEB application can read the information that the Cookie contains.

Suppose that when a user requests access to a page on the of your Web site, your application sends more than one page to the user and a Cookie containing the date and time. The user's browser gets the Cookie at the same time as the page and saves it to a folder on the user's hard disk.

Later, if the user accesses a page on your site again, when the user enters a URL, the browser looks for a Cookie associated with the URL on the local hard disk. If the Cookie exists, the browser sends it to your site along with the page request, and your application can determine the date and time that the user last visited the site. You can send a message to the user based on this information, or you can check the expiration time or perform other useful functions.

Cookies are associated with a Web site rather than a specific page, so browsers and servers will exchange Cookie information regardless of which page the user requests to browse the site. When users visit other sites, each site may send a cookie to the user's browser, and the browser will save all of these cookies separately.

The above is the basic principle of how cookies work. So what's the use of cookies? The most fundamental use of cookies is to help the Web site save information about visitors. More generally, cookies are a way to keep WEB application continuity (that is, to perform state management). Browsers and Web servers are always disconnected in addition to the short actual information exchange phase, and each request sent by the user to the Web server is handled separately, regardless of all other requests. In most cases, however, it is necessary to have the WEB server recognize 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 carts and other user-related information. A Cookie, therefore, acts like a business card, providing related identification information to help the application determine how to proceed.

Cookies can be used for a variety of purposes, all for the purpose of keeping your Web site in mind. For example, a site that implements a poll can simply use a cookie as a Boolean to indicate whether your browser is already voting, so that the site that requires the user to log on will be able to determine whether you have logged in by using a cookie, so you don't have to enter your credentials every time.

For more background information on cookies, it is recommended that you read the "How Internet cookies Work" in Verizon's Web site, address Learningcenter/articles/displayarticle1/0,4065,1022z1,00.html (English). The author explains in detail what cookies are and how cookies exchange information between browsers and servers, and he also sums up the privacy issues involved in cookies.

By the way, do you want to know why they are called "cookies"? The Jargon File (also known as the "the New Hacker") version 4.3.3 gives an accurate definition and a reasonable explanation of the etymology of the term. You can find the relevant entry in Http:// (English).

In the following context, this article assumes that you already know what a cookie is, and assumes that you already understand why you want to use cookies in your application.

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: 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.