C # frequent loss of. net cookies

Source: Internet
Author: User

This is my source code. Could you tell me why the cookie value is often lost?

HttpCookie cookieUrl = new HttpCookie ("User ");
CookieUrl. HttpOnly = true;
CookieUrl. Expires = DateTime. Now. AddDays (1 );
CookieUrl. Values ["BackUrl"] = backUrl;
CookieUrl. Path = "/";
HttpContext. Current. Response. AppendCookie (cookieUrl );

Both methods have been tried, and neither of them can be normal. It starts to be normal and will not be available in a few minutes. Sometimes, as soon as the user logs on, the system immediately prompts that the user has not logged on,

HttpContext. Current. Response. Cookies ["User"]. HttpOnly = true;
HttpContext. Current. Response. Cookies ["User"]. Expires = DateTime. Now. AddDays (1); // expire in 1 day
HttpContext. Current. Response. Cookies ["User"]. Values ["BackUrl"] = backUrl;
HttpContext. Current. Response. Cookies ["User"]. Path = "/";

Please give me some tips. Thank you!

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.