我已经确定了这些预定义的回复:
Ok - 200
NotFound - 404
Exception - 500
Unauthorized - 401
BadRequest - 400
Conflict
Redirect
InvalidModelState
但我找不到任何有关辅助方法存在范围的文档。还有更多吗?
我已经尝试过Microsoft网站,但只找到了these个文档,但他们根本没有列出这些文档。
帮助表示赞赏
答案 0 :(得分:3)
如果您选择ApiController并按F12,您将看到它的定义。列出了所有帮助者。
如果你想创建一个自定义的,这是一个例子:
public class ForbiddenResult : IHttpActionResult
{
private readonly HttpRequestMessage _request;
private readonly string _reason;
public ForbiddenResult(HttpRequestMessage request,string reason)
{
_request = request;
_reason = reason;
}
public ForbiddenResult(HttpRequestMessage request)
{
_request = request;
_reason = "Forbidden";
}
public Task<HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken)
{
var response = _request.CreateResponse(HttpStatusCode.Forbidden,_reason);
return Task.FromResult(response);
}
}