有什么办法可以让我使用新的IHttpActionResult
接口返回一个HttpStatusCode.NoContent
回复消息?
我目前正在使用return new HttpResponseMessage( HttpStatusCode.NoContent );
并想将其转换为return NoContent();
.
IHttpActionResult
已经得到了Ok()
, Conflict()
and NotFound()
但我找不到任何Forbidden()
and NoContent()
我需要在我的项目中使用它。
添加其他结果类型有多容易?
没有方便的方法no-content
结果是因为默认情况下,当操作返回时void
,响应将具有 HTTP 状态 204。
如果您希望在操作上明确指出,您也可以返回StatusCode(HttpStatusCode.NoContent)
从你的行动或
ResponseMessage(new HttpResponseMessage(HttpStatusCode.NoContent)).
Unauthorized() 便捷方法为您提供 401 状态,因此,对于 Forbidden (403),您还必须使用StatusCode(HttpStatusCode.Forbidden)
or
ResponseMessage(new HttpResponseMessage(HttpStatusCode.Forbidden))
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)