In the development process, in order to meet the requirements of customers, we need to implement such a function: click a text link in page A to enter page C, click the return button to return to page A, and page B also has the text link, click to enter When returning to page C, it returns to page B (there can only be one return button in page C). For this reason, I thought of using the Session function, which is to record which page you jumped from when jumping to page C, and then click the return button. When judging the content of the session, decide whether to return to page A or page B.
First, add the code to obtain the page path in the two pages A and B.
string url=Request.CurrentExecutionFilePath.ToString();
//Get the current page The virtual path
Session["URL"]=url;
Response.Redirect("C.aspx",true);
In the C page, first obtain the virtual path
string of the previous page through session url=Session["URL"].ToString ();
Since the first half of the virtual path of the two pages AB is the same, in fact we only need to determine whether it is "A.aspx" or "B.aspx". Therefore, we first use the split method to get the page name we want, and then we can Assign the name to a label and hide the label in the page (whether you need to use Label to save the page name depends on the situation).
string[] split=url.Split(new char[] {'/'} );
int n=split.Length;
string pathname=split[n-1];
Label1.Text=pathname;
Finally, judge in the response event of the return button to decide which page to return:
if (Label1.Text=="A .aspx")
Response.Redirect("A.aspx",true);
else
Response.Redirect("B.aspx",true);