Asp.net Application cookie Sessions Server built-in object (1/4)

Source: Internet
Author: User

Asp tutorial. net application cookie sessions server built-in object

The asp.net tutorial has many built-in objects, including application, response, request, cookie, sessions, cache, server, viewstate, and so on. Through these objects, You can provide some essential functions of the website, such as the absolute path of the file to be obtained, the number of online users, the total number of visitors to the website, and the online shop shopping box.
The cookie object uses the key/value pair method to record data. The statement mycookie. expires = datetime. now. addhours (1) specifies when the data in the cookie expires. In this case, it will expire after 1 hour. If no expiration time is specified, the website will immediately become invalid when it exits.

 

Write

The method of cookie value is as follows:

 

Httpcookie mycookie = new httpcookie ("userinfo ");

Mycookie. value = 2. tostring ();

Mycookie. expires = datetime. now. addhours (1); response. cookies. add (mycookie );

The method to retrieve the cookie value is as follows:

Httpcookie mycookie = request. cookies ["userinfo"];

 

Int num = convert. toint16 (mycookie.

 

Value
 

);

1 2 3 4

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.