加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – HttpResponseException和HttpException之间有什

发布时间:2020-12-15 22:39:19 所属栏目:asp.Net 来源:网络整理
导读:从 http://www.asp.net/web-api/overview/web-api-routing-and-actions/exception-handling HttpResponseException What happens if a Web API controller throws an exception? By default, most exceptions are translated into an HTTP response with sta
从 http://www.asp.net/web-api/overview/web-api-routing-and-actions/exception-handling

HttpResponseException

What happens if a Web API controller throws an exception? By default,
most exceptions are translated into an HTTP response with status code
500,Internal Server Error.

The HttpResponseException type is a special case. This exception
returns any HTTP status code that you specify in the constructor of
the exception.

除了它没有. Fiddler向我显示一个500被退回.

但是,HttpException似乎做了那篇文章.

文件是错误的还是我错过了什么?

UPDATE

在打字时,我有一个想法.我试过两个控制器,一个ApiController和一个标准的MVC控制器.

这两个异常根据他们抛出的控制器的类型相互反向工作.

>使用HttpResponseException从API返回适当的HTTP代码
控制器.
>使用HttpException从一个返回一个适当的HTTP代码
MVC控制器.

解决方法

[将我的更新移至答案]

在打字时,一个ApiController和一个标准的MVC控制器.

这两个异常根据他们抛出的控制器的类型相互反向工作.

>使用HttpResponseException从API控制器返回适当的HTTP代码.>使用HttpException从MVC控制器返回适当的HTTP代码.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读