【发布时间】:2017-07-14 11:06:19
【问题描述】:
考虑以下示例:
[ActionName("SomeTestAction")]
[ResponseType(typeof(SomeObject))]
public IHttpActionResult SomeTestAction(string id)
{
SomeObject o = SomeMethod(id);
if (o == null)
{
var message = string.Format("Nothing found for id = {0}", id);
HttpError err = new HttpError(message);
return Content(HttpStatusCode.NotFound, err);
}
else
{
return Content(HttpStatusCode.OK, o);
}
}
例如,根据数据库查询的结果,此方法可以有两个不同的 ResponseType -s。有没有办法在 WebAPI 的 HelpPages 中指定这种行为,以便用户知道错误响应的样子?
【问题讨论】:
标签: c# asp.net-web-api2