Correctly set the 404 error page for the Asp.net website

Source: Internet
Author: User

Most articles tell you how to search for the Asp.net website to customize the 404 error page:

 

In web. config, find system. Web and configure the following content.
<Customerrors mode = "on" error statuscode = "404" Redirect = "/404.htm">
</Customerrors>

 

In fact, after doing so, we will not be able to find the webpage header information for 404 not found, and we will get the webpage header information for 302 temporary redirection. You can use the check headers tool to view HTTP status codes.

 

So how to correctly configure the custom 404 error webpage for the Asp.net website?

Create a 404. ASPX page, and configure the following in customeerrors in the web. config file:
Customerrors redirectmode = "responserewrite"
Error statuscode = "404" Redirect = "~ /404. aspx "/
/Customerrors

Redirectmode has two attributes.
Responseredirect refers to the URL that redirects the user to the error page and changes the original URL to the error page.
Responserewrite is to direct the user to the error page without changing the original URL in the browser.

 

Then add the following code to the page_load event in the 404. aspx. CS file:

Protected void page_load (Object sender, eventargs E)
{
Response. Status = "404 Not Found ";
}

After this setting, the HTTP status code is 404 Not found.

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.