404 ASP.NET自定义错误页返回302 HTTP状态
在我的asp.net网站我有自定义错误页定义为我的web.config文件如下。
In my asp.net web site I have custom error pages defined as following in my web.config file.
<customErrors mode="On" defaultRedirect="~/defaulterror.htm" >
<error statusCode="404" redirect="~/404.htm" />
当找不到文件时,它正确地显示404.htm页面,但问题是,当我做小提琴手跟踪它返回302 C $ c.This HTTP状态$是搜索引擎的页面索引的一个大问题,由于这种大量的断开的链接仍然被索引,因为这个最近在我的网站。我怎么能prevent返回302 HTTP状态code文件未发现的错误,并返回404文件未找到errors.I正在使用asp.net 3.5。
When file is not found it correctly display 404.htm page but the issue is when I do Fiddler trace it returns 302 as HTTP status code.This is a big issue for search engine page indexing due to this lot of broken links still have been indexed recently because of this in my web site. how can I prevent returning 302 as HTTP status code for file not found errors and return 404 for file not found errors.I am using asp.net 3.5.
谷歌搜索这个问题后,似乎这是默认的行为,微软ASP.NET提供的情况。这是非常糟糕的搜索引擎优化。围绕我发现了一个工作是检查所需的文件是否存在于一个HTTP处理程序(或Global.asax文件),或使用:
After Googling about this issue, it seems that this is the default behavior that Microsoft ASP.NET provides for the situation. This is very bad for SEO. A work around I found is to check whether the requested file exists in an HTTP handler (or global.asax file), or use:
<customErrors mode="On" redirectMode="ResponseRewrite">
<error statusCode="404" redirect="/FileNotFound.aspx" />
</customErrors>
如果所需的文件不存在,则改写请求路径找不到网页文件(如果使用一个HTTP处理程序或Global.asax中),清除背后的404错误页面code中的服务器错误, 404错误头添加到响应手动,而不是等待服务器这样做。
If the requested file does not exist, then rewrite the request path to a file not found page (if using an HTTP handler or global.asax), clear the server errors on the 404 error page code behind, and add a 404 error header to the response manually rather than waiting for server to do so.
Server.ClearError();
Response.Status = "404 Not Found";
Response.StatusCode = 404;