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