Transferred from: http://blog.csdn.net/mycloudke/article/details/9746333
404 Status Code:, meaning that when the user clicks on the page does not exist, improve the user experience, the search engine will abandon the index of the page.
302 Status Code: Search engine will continue to index, which will lead to a large number of different links to the same page, it will affect the search engine trust in the site.
http://www.cloudke.com.cn/with some parameters or nonexistent file names, then jumps to the custom error page, but the returned status is 302.
Workaround:
The first step:
Set the customerrors of Web. config to Off
[CSharp]View Plaincopy
- <customerrors mode="Off" >
- </customErrors>
Then handle the custom error message yourself and add the following code to the Global.asax.cs:
[CSharp]View Plaincopy
- protected void Application_Error (Object sender, EventArgs e)
- {
- if (! request.islocal)// If you are testing locally, remove it!
- {
- Exception LastError = Server.GetLastError ();
- if (lasterror! = null)
- {
- Response.statuscode = 404;
- Response.WriteFile ("~/content/htmltemplate/notfound.htm"); outputs the contents of the Notfound.htm page. You can remove all HTML tags and enter "error" Directly .
- Server.ClearError ();
- }
- }
- }
~/content/htmltemplate/notfound.htm files can only be static files, so that you do not go to the ASP. NET MVC router.
After this preparation, found that there is still a problem, local access 404 can go to the custom page, but remote access is not, you need to configure IIS
Open error page, edit page 404
This file path is a custom error page 404.
OK, let's Test it again:
The test results are normal.