Cookies are easy to set and use. Therefore, no expires issue is found during the process of Directly Reading and Writing cookies.
After obtaining a cookie instance from the request, if the cookie is sent to the client again without resetting the expires, the expires page expires.
For example:
First, send cookies on a page.
Httpcookie _ currentcookie;
_ Currentcookie = new httpcookie ("test ");
_ Currentcookie. expires = datetime. Now. addyears (1 );
Response. appendcookie (_ currentcookie );
Then another page receives
Httpcookie _ currentcookie;
_ Currentcookie = request. Cookies ["test"];
In this case, we can obtain and display the expiration time of expires.
Response. Write (_ currentcookie. expires. tostring ());
As usual, we didn't change this cookie. After obtaining the cookies, we sent them to the browser, which should not change.
But you will actually find a problem.
_ Currentcookie ["test"]. expires changes to 0001-1-1. After the page is closed, it expires.
Through the above experiments, we found that we could not actually obtain the expires attribute of cookies. Therefore, when using response. if expires is not reset for the instance during appendcookies, The expires will be sent with the default setting (the page is closed and expired, therefore, if you want to send a cookie each time, you must reset the expiration time.
This problem occurs when I encapsulate cookies. Although cookies are frequently used in the past, this time we want to encapsulate them into an independent class, so we are streamlining the process. Code In the process!
It seems that no matter how familiar things are, there will always be a strange side, and you need to learn more!
Of course, this is in. net2.0 C #. It seems that 1.1 can obtain the expires attribute of the cookie from the request.
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