Detailed description of Request. UrlReferrer

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.