Asp: Cookie Application Guide, detailed code and tutorials
Source: Internet
Author: User
In fact, in web development, a cookie is only a text file. When a user accesses a website, it is stored on the user's computer.
Some information, which can be extracted by the web when the user visits the site again in the future.
Although it sounds like a cookie is nothing exciting now, you can actually use it to implement many meaningful functions! For example, you can place
A survey Q & A table that asks visitors about their favorite colors and fonts and then customizes the user's web interface based on these. You can also save the visitor's logon password.
When a visitor visits the site again, he or she does not need to enter a password to log on.
Of course, cookies also have some shortcomings. First, because the cookie function can be used to program some bad attempts, most browsers have security settings.
You can set whether to allow or accept cookies. Therefore, you cannot use cookies at any time. Furthermore, visitors may intentionally or unintentionally delete
Cookie. When the visitor's machine crashes, or the hard disk is reformatted and the system is installed, all the previously stored cookies will be lost. Last point:
Some initial browsers do not support cookies.
What can cooklie do?
There are two basic methods to use cookies:
1. Write the cookie to the visitor's computer (use the RESPONSE command)
2. Retrieve the cookie from the visitor's computer (use the REQUEST command)
Basic cookie creation syntax
Response. Cookies ("CookieName") = value
Execute the following code to create a cookie on the visitor's computer. The cookie name is VisitorName and the value is Ken.
Response. Cookies ("VisitorName") = "Ken"
Execute the following code to create a cookie on the visitor's computer. The cookie name is VisitorName and the value is the UserName value in the form.
Response. Cookies ("VisitorName") = Request. Form ("UserName ")
Basic syntax for reading cookies
Request. Cookies ("CookieName ")
You can treat the Request value as a variable. Execute the following code to retrieve the cookie value named "KensCookie" and save it to the variable MyVar:
MyVar = Request. Cookies ("KensCookie ")
Run the following code to determine whether the cookie value named "KensCookie" is "Yes ":
If Request. Cookies ("KensCookie") = "Yes" then
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