Set the 404 page in ASP. NET and output the 404 status code.

Source: Internet
Author: User

1. Configure web. config

The code is as follows: Copy code

<CustomErrors redirectMode = "ResponseRewrite" defaultRedirect = "/404. aspx">
<Error statusCode = "404" redirect = "/404. aspx"/>
</CustomErrors>

2. Set 404. aspx

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, I didn't tell you that the browser does not return the 404 status code and it will be 200 or 302. This is unfriendly to the search. To solve this problem, let's look down.

Now we add the following code to the 404. aspx background code:

The code is as follows: Copy code
Protected void Page_Load (object sender, EventArgs e)
{
Response. ClearContent ();
Response. Status = "404 Not Found ";
}

The Response. ClearContent () method clears other possible outputs so that normal display of our 404 page is not affected. So far, we have solved the configuration of ASP. NET 404 errors perfectly. Similarly, we can add 500 error processing in the same way.

Ps: of course, if it is iis, we can use iis to define the 404 error page.

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.