Request. urlreferrer can obtain information about the URL of the client's last request.
In this way, we can return to the "Previous Page" through this attribute. The example is as follows:
1. Obtain and store the information in page_load.
Page_load (Object OBJ, eventargs E)
{
If (! Ispostback)
{
If (request. urlreferrer! = NULL )//
{
Viewstate ["urlreferrer"] = request. urlreferrer. tostring ();
}
}
}
After the page is sent back, the request. urlreferrer will be changed and directed to the current page. Therefore, you need to make a judgment that this information is only stored on the first request page.
Because the previous URL may not exist, you need to make a judgment and store it only when request. urlreferrer exists.
2. Use this information in the return function.
Void return ()
{
If (viewstate ["urlreferrer"]! = NULL)
Response. Redirect (viewstate ["urlreferrer"]. tostring ();
}
when using request. note the following when urlreferrer:
1. if the document. the location method is used to navigate to the current page, request. urlreferrer returns a null value
2. if there are two pages a and B, directly request page A in the browser, and navigate to page B in the page_load event of page A, then request. urlreferrer returns NULL. Because the page has not been initialized in the page_load event, you cannot record the information of the current page. If you navigate to page B, you cannot obtain the information on the previous page.
3. clicking the refresh button does not change the request. urlreferrer