How to retain the previous page when refreshing the asp.net framework page

Source: Internet
Author: User

How to retain the previous page when refreshing the asp.net framework page

Assume that right. aspx is on the right of the Framework page, and newPage. aspx is on.

 

 

Right. aspx

Protected void Page_Load (object sender, EventArgs e)
{
HttpCookie;
If (Request. Cookies ["getUrl"]! = Null)
{
Cookie = Request. Cookies ["getUrl"];
If (cookie ["url"]. ToString (). ToLower ()! = "Right. aspx ")
Response. write ("<script> parent.doc ument. all ['right']. src = \ "" + cookie ["url"] + "\"; </script> ");
}
}
-------------------------

Common. cs

Public static void setCookie (string url)
{
HttpCookie getUrl = new HttpCookie ("getUrl"); // declare a cookie
GetUrl. Values. Add ("url", url); // Save the url to the cookie
// GetUrl. Expires = DateTime. Now. AddDays (1); // set the COOKIE expiration event to one day, and do not set the storage time, so that the browser closes the COOKIE and becomes invalid.
HttpContext. Current. Response. Cookies. Add (getUrl); // confirm that the cookie is being written.
}

----------------------

NewPage. aspx

Protected void Page_Load (object sender, EventArgs e)
{
If (! IsPostBack)
{
String url = Request. RawUrl; // Request. UrlReferrer. ToString (); // obtain
Url = url. Substring (url. LastIndexOf ('/') + 1 );
Common. setCookie (url );
}


Author: luojianfeng

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.