Detailed Request.UrlReferrer

Request.UrlReferrer can get information about the client's last request url.
  So that we can return by this property to "previous",
the following example
    

1.      First, obtaining and storing the information in Page_load

Page_load(object obj,EventArgs e)
             {
                     if(!IsPostBack)
                    {
                         if(Request.UrlReferrer!=null)  //
                        {
                                                      ViewState["UrlReferrer"]=Request.UrlReferrer.ToString();
                        }
                    }
             }

l        page will change after postback Request.UrlReferrer, which points to the current page, so the need for judgment: only when the first request for a page only to save the message

l        because of possible "on time" the url does not exist, it is necessary to judge, be stored only in case of presence Request.UrlReferrer
            

2.      then use that information in the function returns

void Return()

{

    if(ViewState["UrlReferrer"]!=null)

        Response.Redirect(ViewState["UrlReferrer"].ToString();

}

Also note that when using Request.UrlReferrer: 
1. If using the previous page to the current page to navigate document.location, Request.UrlReferrer returns NULL
2. If A, B two pages, directly in the browser request A page, in the page's Page_Load event a to B navigation page,     Request.UrlReferrer return empty. Because the  page has not been initialized Page_load event, it is impossible to record information, navigation current page to page b will not be able to obtain information on the previous page   
3. Click the Refresh button does not change Request.UrlReferrer

Reproduced in: https: //www.cnblogs.com/zhangchenliang/archive/2011/07/18/2109175.html

Guess you like

Origin blog.csdn.net/weixin_33691598/article/details/93494948