Before use, make a judgment:
If (Request! = Null & Request. UrlReferrer! = Null & Request. UrlReferrer. PathAndQuery! = Null)
{
String previusurl = Request. UrlReferrer. PathAndQuery;
}
Instance description:
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 ",
Example:
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 ();
}
}
}
L 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: This information is stored only when the page is requested for the first time.
L because the previous url may not exist, you need to make a judgment. It is stored only when Request. UrlReferrer exists.
2. Use this information in the return function.
Void Return ()
{
If (ViewState ["UrlReferrer"]! = Null)
Response. Redirect (ViewState ["UrlReferrer"]. ToString ();
}
Note the following when using Request. UrlReferrer:
1. If the document. location method is used on the previous page 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
In order to not initialize the page in the Page_load event, you cannot record the information on 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 Request. UrlReferrer.