Website Optimization-Asp.net page Jump mode Optimization

Source: Internet
Author: User
Tags microsoft iis

When developing Asp.net, redirecting between different pages is a common problem, when a complex logic cannot be divided into two or more pages for processing on a single page, you need to jump between pages. you can log on most of the pages ..

ASP. net uses the most jump is response. redirect. This command can directly redirect requests to a relative or absolute path. it will directly redirect the HTTP stream blocking of the current page to the new URL.

Server. transfer: this command is directly redirected by the IIS server on the server side. The jump path must be a relative path, that is, the path or virtual eye directory under the same website. it cannot be an absolute Internet path, because

It is directly requested by the same HTTP handle on the current request page to specify the path on the same site.

Where are their differences? Let's first look at the HTTP header and first look at response. Redirect.

Protected void page_load (Object sender, eventargs E)
{
Response. Redirect ("/redirect. aspx"); // redirect directly to the path on this site
}

Http://xml.test.com/HttpStatus.aspx --> This refers to the page where my request is executed

GET/httpstatus. aspx HTTP/1.1
HOST: xml.test.com
User-Agent: Mozilla/5.0 (windows; U; Windows NT 6.1; ZH-CN; RV: 1.9.0.14) Gecko/2009082707 Firefox/3.0.14
Accept: text/html, application/XHTML + XML, application/XML; q = 0.9, */*; q = 0.8
Accept-language: ZH-CN, ZH; q = 0.5
Accept-encoding: gzip, deflate
Accept-charset: gb2312, UTF-8; q = 0.7, *; q = 0.7
Keep-alive: 300
Connection: keep-alive

HTTP/1.x 302 found --> pay attention to this 302
Cache-control: Private
Content-Type: text/html; charset = UTF-8
Location:/redirect. aspx
Server: Microsoft-Microsoft IIS/7.5
X-ASPnet-version: 2.0.50727
X-powered-by: ASP. NET
Date: Sun, 01 Nov 2009 12:12:45 GMT
Content-Length: 133
----------------------------------------------------------
Http://xml.test.com/redirect.aspx --> This is the page for redirect requests

GET/redirect. aspx HTTP/1.1
HOST: xml.test.com
User-Agent: Mozilla/5.0 (windows; U; Windows NT 6.1; ZH-CN; RV: 1.9.0.14) Gecko/2009082707 Firefox/3.0.14
Accept: text/html, application/XHTML + XML, application/XML; q = 0.9, */*; q = 0.8
Accept-language: ZH-CN, ZH; q = 0.5
Accept-encoding: gzip, deflate
Accept-charset: gb2312, UTF-8; q = 0.7, *; q = 0.7
Keep-alive: 300
Connection: keep-alive

HTTP/1.x 200 OK
Cache-control: Private
Content-Type: text/html; charset = UTF-8
Content-encoding: Gzip
Vary: Accept-Encoding
Server: Microsoft-Microsoft IIS/7.5
X-ASPnet-version: 2.0.50727
X-powered-by: ASP. NET
Date: Sun, 01 Nov 2009 12:12:45 GMT
Content-Length: 489

And the URL in the address bar is positioned to the http://xml.test.com/redirect.aspx

Let's take a look at the execution on the request page.

Public partial class httpstatus: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
Server. Transfer ("/redirect. aspx ");
}
}

The HTTP request information is

 

Http://xml.test.com/HttpStatus.aspx

GET/httpstatus. aspx HTTP/1.1
HOST: xml.test.com
User-Agent: Mozilla/5.0 (windows; U; Windows NT 6.1; ZH-CN; RV: 1.9.0.14) Gecko/2009082707 Firefox/3.0.14
Accept: text/html, application/XHTML + XML, application/XML; q = 0.9, */*; q = 0.8
Accept-language: ZH-CN, ZH; q = 0.5
Accept-encoding: gzip, deflate
Accept-charset: gb2312, UTF-8; q = 0.7, *; q = 0.7
Keep-alive: 300
Connection: keep-alive

HTTP/1.x 200 OK
Cache-control: Private
Content-Type: text/html; charset = UTF-8
Content-encoding: Gzip
Vary: Accept-Encoding
Server: Microsoft-Microsoft IIS/7.5
X-ASPnet-version: 2.0.50727
X-powered-by: ASP. NET
Date: Sun, 01 Nov 2009 12:17:21 GMT
Content-Length: 489

 

The comparison between the two different requests clearly shows that the HTTP request is completely different.

And the current URL is still in progress.

Google also has some suggestions on searching. Do not use 302 redirection as much as possible. Redirect will generate a targeted 302 status, which is slightly different on the performance layer, but may be somewhat delayed for search engines.

Let's take a look at Google's explanation.

If you need to change the URL of a page as it is shown in search engine results, we recommended that you use a server-side 301 redirect. this is the best way to ensure that users and search engines are directed to the correct page. the 301 status code means that a page has permanently moved to a new location.

Http://www.google.com/support/webmasters/bin/answer.py? Hl = en & Answer = 93633

In addition, server. Execute is rarely used, and its function is to reverse the content of the jump request page back to the current URL.

Httpstatus. aspx

Public partial class httpstatus: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
Server. Execute ("/redirect. aspx ");
}
}

Redirect. aspx

Public partial class redirect: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
Response. Write ("server. Execute ");
}
}

When you directly request httpstatus. aspx, the page displays server. Execute, which directly adds the value of the user request page to the current page. Its HTTP request information is as follows:

 

Http://xml.test.com/HttpStatus.aspx

GET/httpstatus. aspx HTTP/1.1
HOST: xml.test.com
User-Agent: Mozilla/5.0 (windows; U; Windows NT 6.1; ZH-CN; RV: 1.9.0.14) Gecko/2009082707 Firefox/3.0.14
Accept: text/html, application/XHTML + XML, application/XML; q = 0.9, */*; q = 0.8
Accept-language: ZH-CN, ZH; q = 0.5
Accept-encoding: gzip, deflate
Accept-charset: gb2312, UTF-8; q = 0.7, *; q = 0.7
Keep-alive: 300
Connection: keep-alive
Cache-control: Max-age = 0

HTTP/1.x 200 OK
Cache-control: Private
Content-Type: text/html; charset = UTF-8
Content-encoding: Gzip
Vary: Accept-Encoding
Server: Microsoft-Microsoft IIS/7.5
X-ASPnet-version: 2.0.50727
X-powered-by: ASP. NET
Date: Sun, 01 Nov 2009 12:32:03 GMT
Content-Length: 552

 

For Google's discussion, we use server-side redirection. server. transfer is the server-side jump, and redirect is the client-side request jump. But when will redirect be used to use server. transfer?

Summary:

Use redirect to redirect a user to a page on another server.
When you need to redirect a user to a non-ASPX page, for example, HTML uses redirect
When the query string needs to be retained to the server as part of the URL, because the other two methods cannot achieve two PostBack operations, the data is first brought back to the server using Redirect
Switch between aspx pages (logon not involved) Using Transfer

By the way, how to use the Redirect method to use Chinese Characters in query strings is often garbled because URLs do not support Chinese characters. In this case, the conversion is required:
String message = server. urlencode ("Liang Yuanhua blog ");

Controls on. NET

I. server controls
Hyperlink
Use the navigateurl attribute to specify the URL to jump.
It is mainly used by the user to determine when to convert the page,ProgramTo control the conversion target.
Ii. Program Control
1. response. Redirect ()
Server -------- notify client ---------- request jump to server
It is mainly used to pass the query string as part of the URL to another page, or the page to jump to is an HTML page
2. server. Transfer ()
The biggest feature of this method is that the URL is still the URL of the page before the jump.
It is mainly used to transfer the execution process to another ASPX page of the same web server. Because it is retained after the jump
Request and session values, and the data on the page before the jump can be used.

Another value is:
3. server. Execute ()
After this method is executed, the program control will return to the jumpCodeThe Next Generation Code is equivalent to our modal window.
The Return Value of the redirected page.
Sever.exe cute this method is mainly used in the page design, and he must jump to the page under the same site. This method needs to be used to insert the output results of a page to another ASPX page. Most of them are in the table, where a page is nested to another page.
Use redirect to redirect a user to a page on another server.
Execute is used to insert the output result of the ASPX page to another ASPX page.
· If you want to capture the output result of An ASPX page and insert the result to a specific location of another ASPX page, use server. Execute.
· To ensure that the HTML output is valid, use response. Redirect instead of server. Transfer or server. Execute.

 

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.