Request.UrlReferrer USES details

  • 2020-06-03 06:19:21
  • OfStack

Request. UrlReferrer can get information about url that the client last requested.
So we can use this property to go back to the previous page,
The sample is as follows
1. First get and store this information in Page_load
 
Page_load(object obj,EventArgs e) 
{ 
if(!IsPostBack) 
{ 
if(Request.UrlReferrer!=null) // 
{ 
ViewState["UrlReferrer"]=Request.UrlReferrer.ToString(); 
} 
} 
} 

The page postback changes Request.UrlReferrer to point to the current page, so you need to determine that this information is only saved on the first page request
Since it is possible that url "last time" does not exist, it needs to be judged that it is stored only in the presence of ES15en.UrlReferrer
2. Then use this information in the return function
 
void Return() 
{ 
if(ViewState["UrlReferrer"]!=null) 
Response.Redirect(ViewState["UrlReferrer"].ToString(); 
} 

Also note when using ES21en. UrlReferrer:
1. If the previous 1 page USES the document.location method to navigate to the current page, Request.UrlReferrer returns a null value
2. If there are two A and B pages, request A page directly in the browser, navigate to B page in the Page_Load event in A page, then Request.UrlReferrer returns empty. Because the page has not been initialized in the Page_load event, the information for the current page cannot be logged, and navigation to the b page does not retrieve the information from the previous page
3. Clicking the refresh button will not change ES42en.UrlReferrer

Related articles: