文章内容

2017/10/29 10:18:29,作 者: 黄兵

软404错误

最近在使用Google Search Console的时候,提示有两个404软错误,如下所示:

出现这个错误有什么问题呢?

引用:Search Console 帮助里面的内容如下;

返回成功代码,而不是 404/410(未找到)或 301(已移动),这是一种不好的做法。成功代码等于告知搜索引擎,通过该网址可以找到实际的网页。因此,该网页可能会列在搜索结果中,搜索引擎将继续尝试抓取这个不存在的网址,而不是将时间用于抓取您的实际网页。
您的服务器会针对不存在的网页返回除 404 或 410 之外的代码(或会将用户重定向至其他网页(例如首页),而不是返回 404 代码)。这不仅会给搜索者带来糟糕的体验,也会对搜索引擎的操作造成负面影响。

看样子很严重,要修改。具体如何修改,参加以下操作:

1、在自定义404的控制器写如下内容:

public ActionResult System_notfound()
{
// If you're running under IIS 7 in Integrated mode set use this line to override
// IIS errors:
Response.TrySkipIisCustomErrors = true;

// Set status code and message; you could also use the HttpStatusCode enum:
// System.Net.HttpStatusCode.NotFound
Response.StatusCode = 404;
Response.StatusDescription = "Page not found";

return View();
}

我的web.config文件定义404错误页面如下:

<customErrors mode="RemoteOnly" defaultRedirect="Error">
<error statusCode="500" redirect="/Home/System_Error" />
<error statusCode="404" redirect="/Home/System_notfound" />
</customErrors>

Response.TrySkipIisCustomerErrors的定义如下:

获取或设置一个值,该值指定是否禁用 IIS 7.0 自定义错误。

如果禁用了 IIS 自定义错误,则为 true;否则为 false

首先禁用IIS自定义错误,之后再向客户端发送404错误。

修改之后的效果如下:


可以看到,首先一个302找到内容,之后跳到404错误页面,同时显示404错误。

参考资料:

Best way to implement a 404 in ASP.NET

软 404 错误
HttpResponseBase.TrySkipIisCustomErrors 属性

黄兵个人博客原创。

转载请注明出处:黄兵个人博客 - 软404错误

分享到:

发表评论

评论列表