Implementation of Asp. Net 404 page and 301 redirection

Source: Internet
Author: User

To some extent, 301 redirection has nothing to do with 404 pages. Why should I get them together? because production is easy to implement, I will introduce them together.

How to set the 404 page method record in asp.net.

Next, let's take a look at the previous setting method, in the web. config file:

The Code is as follows: Copy code

<Configuration>
<System. web>
<CustomErrors mode = "RemoteOnly" defaultRedirect = "404. aspx">
</CustomErrors>
</System. web>
</Configuration>

Of course, we have created 404 page 404 before. aspx, I believe many people think this is okay, but we ignore it. Here we only do simple redirection and do not tell the browser that the webpage does not exist. The following section is taken from Sun Ming's blog:

404 error: seo/seo.html "target =" _ blank "> the search engine uses the HTTP status code to identify the webpage status. When the search engine gets an error link, the website should return a 404 status code, telling the search engine to discard the index of the link. If a 200 or 302 status code is returned, the search engine creates an index for the link, which leads to a large number of different links pointing to the same webpage content. As a result, the search engine significantly reduced its trust in the website. -- This problem exists in many websites: The 404 page returns the 200 or 302 status code instead of the 404 status code.
Therefore, the following code is added in the 404. aspx file:

The Code is as follows: Copy code

Protected void Page_Load (object sender, EventArgs e)
{
Response. Status = "404 Not Found ";
}

By using httpwatch, we can find that 404 status code is returned correctly when you access a page that does not exist on the website.

So how can we set the 301 page? Let's take a look at it.


For example, if the original domain name on this site is www.hzhuti.com, All accesses to this domain name will be redirected to www. bKjia. c0m; Add the following code to the page to be switched:

The Code is as follows: Copy code

Protected void Page_Load (object sender, EventArgs e)
{
Response. Clear ();
Response. StatusCode = 301;
Response. Status = "301 Moved Permanently ";
Response. AddHeader ("Location", "http://www.bKjia. c0m ");
}

Using this method, this site switches the original domain name to www. bKjia. c0m. Now the domain name should be easy to remember. Thank you for your support.

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.