You have predefined methods for most common status codes.
Ok(result)
returns 200
with responseCreatedAtRoute
returns 201
+ new resource URLNotFound
returns 404
BadRequest
returns 400
etc. See BaseController.cs
and Controller.cs
for a list of all methods.
But if you really insist you can use StatusCode
to set a custom code, but you really shouldn't as it makes code less readable and you'll have to repeat code to set headers (like for CreatedAtRoute
).
public ActionResult IsAuthenticated()
{
return StatusCode(200, "123");
}