其中HTTP状态codeS,用于支付MVC的错误处理 [英] Which HTTP Status Codes to cover for MVC error handling

查看:126
本文介绍了其中HTTP状态codeS,用于支付MVC的错误处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发在我的错误处理code自定义错误页为我的MVC应用程序。但我不清楚的状态codeS我的意思的HTTP覆盖。

I'm currently developing custom error pages in my error handling code for my MVC application. But I'm unclear as to which HTTP status codes I'm meant to cover.

问:有应照顾HTTP状态codeS的典型列表

Question: is there a typical list of HTTP status codes that should be catered for?

解释如何做MVC的错误处理和自定义错误页,但似乎只显示几个HTTP状态codeS的金润文章:403,404和500在他们的错误处理code。什么HTTP状态code:408作为一个例子吗?如果这种覆盖?关于其他状态codeS的每吨什么 - HTTP状态codeS上维基

Alot articles which explain how to do MVC error handling and custom error pages but appear to only show several of the HTTP Status Codes: 403, 404, and 500 in their error handling code. What about HTTP Status Code: 408 as an example? Should this be covered? What about the tonne of other status codes - HTTP status codes on wiki

这可能听起来像一个愚蠢的问题,但我真的不知道答案并不能找到这个信息。我失去了一些东西在这里,即只能状态codeS的一个子集,被覆盖?

This may sound like a dumb question, but I really don't know the answer and can't find an information on this. Am I missing something here, i.e. should only a subset of status codes be covered?

如果有帮助,下面就是我为我的MVC错误处理完成。这code(到目前为止与我已经做了小测试)覆盖404,以及所有类型50X异常:

If it helps, below is what I've done for my MVC error handling. This code (so far with the little testing that I've done) covers 404, and all 50x type exceptions:

1 在web.config中,并为每个HTTP状态code我想捂住条目

1 In web.config, and entry for each HTTP status code I want to cover

<httpErrors errorMode="Custom" existingResponse="Replace" >
  <remove statusCode="403" />
  <remove statusCode="404" />
  <remove statusCode="500" />
  <error statusCode="403" responseMode="ExecuteURL" path="/Error/Forbidden" />
  <error statusCode="404" responseMode="ExecuteURL" path="/Error/NotFound" />
  <error statusCode="500" responseMode="ExecuteURL" path="/Error" />
</httpErrors>  

2 错误控制器

    namespace MyApp.Controllers
    {
      public class ErrorController : Controller
      {
      public ActionResult Index()
      {
        return View();
      }
      public ActionResult Forbidden()
      {
        return View();
      }
      public ActionResult NotFound()
      {
        return View();
      }

3 用户友好的错误页面:

/Views/Shared/Index.cshtml
/Views/Shared/Forbidden.cshtml
/Views/Shared/NotFound.cshtml

4 对于ELMAH记录

在2015年11月2日进一步的调查结果

东西我刚刚发现,一直盯着我,我已经错过了......在IIS脸上,遮住了默认的错误页面是:

Something I've just discovered that has been staring me in the face which I've missed... In IIS, the default Error pages covered are:


  • 401 - 未授权

  • 403 - 禁止

  • 404 - 找不到

  • 405 - 不允许的方法

  • 406 - 不接受

  • 412 - precondition失败

  • 500 - 内部服务器错误

  • 501 - 未执行

  • 502 - 错误网关

如果这是良好的范围微软已经设置的话,我将在本去为指导去向前!

If this is good range Microsoft have set, then I will go by this as a guide going forwards!

推荐答案

这是有趣的问题,恕我直言。

An interesting question, IMHO.

这三个错误(403,404和500)是可以发生在一个标准的浏览器访问您的网站的真实用户的最常见错误。

These three errors (403, 404 and 500) are the most common errors that can happen to the real user accessing your site with a standard browser.

在另一方面,HTTP标准是为服务器和代理开发商为了定义如何两侧应操作写入。当然,标准的浏览器如IE,Chrome和Firefox等,以及标准的机器人像谷歌或Bing搜索引擎正确地满足要求,但一些专有的书面剂可以发送畸形的请求,该标准规定了一套$ C的$ CS服务器应该在这种情况下发送。例如,如果Content-Length字段错过服务器返回错误code 411然而,你不应该为这种情况的用户友好的页面。

On other hand, the HTTP standard was written for both server and agent developers in order to define how both sides should operate. Naturally, the standard browsers like IE, Chrome, Firefox, etc. as well as the standard robots like Google or Bing bots correctly fulfill the requirements, but some proprietary written agent may send a malformed request, and the standard provides the set of codes the server should send in this situation. For example, if the Content-Length field is missed the server returns the error code 411. However, you shouldn't provide user-friendly pages for such a situation.

在code 408(请求超时)在标准解释如下:

The code 408 (Request timeout) is explained in the standard as following:

客户没有产生的时候,该服务器是prepared等待,客户可以重复没有以后的任何时间修改请求中的一个请求。

"The client did not produce a request within the time that the server was prepared to wait. The client MAY repeat the request without modifications at any later time."

和它也不是一个情况下,你应该让用户友好的页面。

and it also not a case you should make user-friendly page for.

为了使长话短说,不要担心:)

To make a long story short, don't worry :)

这篇关于其中HTTP状态codeS,用于支付MVC的错误处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆