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.