[Original] analysis of response. Redirect () method in ASP. NET

Source: Internet
Author: User

In this article, we will use the HTTP analysis tool Fiddler to analyze the entire process of the response. Redirect () method.

 

First create a new website in Visual Studio and write Response. Redirect ("http://www.baidu.com") in the page_load event of the default page ");

Then add a page_loadcomplete event processing method.

The final result is as follows:

Set breakpoints on lines 12 and 17 to facilitate observation of the entire process.

Open Fiddler to observe the HTTP data throughout the process.

Click "debug ".

The program starts execution.

In this case, a piece of data appears in Fiddler:

This is a GET request sent by the browser to http: // localhost: 53765/website2/default. aspx.

 

This thhp GET request causes the server-side program to start execution. When the execution reaches 12 rows, a breakpoint occurs, so it stops. At this time, the response. Redirect statement has not been executed.

At this time, the server has not responded to the request sent by the browser just now, so in Fiddler, the response to this HTTP request is not read.

Then I press F5 on the server side to continue the program execution. After the program executes the response. Redirect statement, the server-side response is received in Fiddler.

Obviously, the server did not return the HTML data of the default page to our page, but instead gave a 302 found and "http://www.baidu.com" in location ", this is telling the browser: Please send an HTTP request again, the requested URL is "http://www.baidu.com"

The browser re-issued an HTTP request as instructed.

This time, a GET request was sent to Baidu's server.

Then Baidu returns the following data:

This is 200 OK, content-type is HTML, followed by HTML code on the Baidu Homepage

Then, the browser parses the HTML code based on the returned data and displays Baidu's appearance on our screen.

In addition, during this process, we noticed that the page_loadcomplete () method is not executed, which means that when the server executes response. when a redirect statement is executed, the lifecycle of the page is immediately interrupted, and information is directly returned to the client for redirection.

The whole process is like this.

In addition

ASP. NET 4 adds a redirectpermanent method, which is also a redirection method, but the generated HTTP response status is not 302, but 301 (permanent jump)

301 is the most user-friendly redirection Method for search engines.

So what is search engine friendly?

For example, if you have a website http://www.foo.com, when people access the http://www.foo.com URL, You redirect them to the ingress.

If we redirect an address in the 301 redirection mode, the search engine will take the PageRank and other information of the old address to the new address, at the same time, the original old address is completely discarded in the search engine index library.

This is just a simple description. In fact, the question about the friendliness of search engines is very complicated. Please search for more information by yourself.

 

Refer:

<Http://www.cnblogs.com/xl888/archive/2008/10/28/1320945.html>

<Http://www.webconfs.com/redirect-check.php>

<Http://www.webconfs.com/how-to-redirect-a-webpage.php>

<Http://www.cnblogs.com/longgel/archive/2010/06/02/1749897.html>

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.