Asp. Introduction of Cookie reading and writing method in net

Source: Internet
Author: User
Tags datetime net tostring access
Cookies (instances of HttpCookie) provide a way to store user-specific information in a WEB application. For example, when a user accesses your site, you can use cookies to store user preferences or other information. When the user accesses your Web site again, the application can retrieve previously stored information.

Asp. NET cookies: Creating cookie Methods (1)

response.cookies["UserName"]. Value = "admin";

response.cookies["UserName"]. Expires = DateTime.Now.AddDays (1);

If no expiration time is set, the cookie information is not written to the user's hard disk, and the browser shutdown is discarded.

Asp. NET cookies: Creating Cookie Methods (2)

HttpCookie acookie = new HttpCookie ("lastvisit");

Last Access time

Acookie.value = DateTime.Now.ToString ();

Acookie.expires = DateTime.Now.AddDays (1);

RESPONSE.COOKIES.ADD (Acookie);

Asp. NET Cookies: Access Cookie method (1)

if (request.cookies["userName"]!= null)

Label1.Text = Server.HTMLEncode (request.cookies["UserName"). Value);

Access Cookie Method (2)

if (request.cookies["userName"]!= null) {

HttpCookie acookie = request.cookies["UserName"];

Label1.Text = Server.HTMLEncode (Acookie.value);

}

Asp. NET cookies: Creating a multivalued cookie method (1)

response.cookies["UserInfo" ["userName"] = "admin";

response.cookies["UserInfo" ["lastvisit"] = DateTime.Now.ToString ();

response.cookies["UserInfo"]. Expires = DateTime.Now.AddDays (1);

Asp. NET cookies: Creating a multivalued Cookie method (2)

HttpCookie Acooki



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.