When searching online for websites on how to customize 404 error pages, most articles tell you that you can find and configure the following content.
Copy the codeThe code is as follows:
<customErrors mode="On" error statusCode="404" redirect="/" >
</customErrors>
In fact, after doing this, you can't get the web header information of the 404 page not found, and you get the web header information of the 302 temporary redirection. You can use the Check Headers Tool tool to view HTTP Status Codes.
So how to correctly configure the website’s custom 404 error page?
First create a page, and then configure it in the customerErrors under the file as follows:
customErrors redirectMode="ResponseRewrite"
error statusCode="404" redirect="~/"/
/customErrors
RedirectMode has two properties.
ResponseRedirect refers to the redirection of the user to the error page and the original URL is changed to the URL of the error page.
ResponseRewrite refers to directing the user to an error page without changing the original URL in the browser.
Then in the file, add the following code to the Page_Load event:
Copy the codeThe code is as follows:
protected void Page_Load(object sender, EventArgs e)
{
= "404 Not Found";
}
After this setting, the HTTP Status Code will be 404 Not Found.