ASP. NET Response. Redirect: Session loss

Source: Internet
Author: User

A recent project found that the Session will be lost after Response. Redirect. After two days, the problem was finally found.

Problem code

Session ["xxx"] = xxx;
Response. Redirect ("yyy. aspx ");

When the page jumps to yyy. aspx and the Session is lost, Access Session ["xxx"] To get null.

Cause: When asp.net executes Response. during Redirect, the current Response is forcibly terminated. Instead of sending the cookie on the current page to the browser, a command is sent to tell the browser to resend a new HTTP request to the new URL, as a result, the current Session is lost.

To solve this problem, set the Session when receiving the Get request on the current page, so that the browser will record the current Session Id. When the browser sends a Post request to the current page, the Server does not need to send the Session ID cookie to the browser.

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.