asp.net-mvc – HttpResponseException和HttpException之间有什么区别?

前端之家收集整理的这篇文章主要介绍了asp.net-mvc – HttpResponseException和HttpException之间有什么区别?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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代码.

原文链接:https://www.f2er.com/aspnet/249412.html

猜你在找的asp.Net相关文章