Marcus H Marcus H - 1 year ago 93
C# Question

Which implementations of IHttpActionResult exist

I have identified these pre-defined responses:

Ok - 200
NotFound - 404
Exception - 500
Unauthorized - 401
BadRequest - 400

But I can't find any docs about the total range of helper methods that exist..Are there any more?

I've tried Microsoft site and only found these docs but they don't list them at all..

Help appreciated

Answer Source

If you select ApiController and press F12 you will see the definition of it. There are listed all the helpers.

enter image description here

If you want to create a custom one here is an example:

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);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download