【发布时间】:2013-11-24 23:35:06
【问题描述】:
我已经看到使用一些新的 IHttpActionResults 表示 OK,NotFound 的示例。
我没有看到任何使用Unauthorized() 的东西。
我现有的代码如下所示:
catch (SecurityException ex)
{
request.CreateResponse(HttpStatusCode.Unauthorized, ex.Message);
}
我想用这个替换它:
catch (SecurityException ex)
{
response = Unauthorized();
}
但我没有看到任何过载来传递异常详细信息。
另外,IHttpActionResult 相当于返回 500 错误?
catch (Exception ex)
{
response = request.CreateErrorResponse(HttpStatusCode.InternalServerError,
ex.Message);
}
【问题讨论】:
-
我发现 response = InternalServerError(ex);解决 500 问题。我仍在寻找接受字符串消息的 Unauthorized 示例。