5

You can return the http status code along with the response object using:

 return Ok(responseObject);
 return BadRequest(responseObject);
 return NotFound(responseObject);

But what about you want to return your own custom http status code? 402, 429, 500, 501 etc

3
  • presumably Ok, BadRequest etc implement some interface that you can also implement in a userland class and return an instance of that class? Commented Mar 30, 2017 at 1:53
  • 2
    why did you ask this question? Commented Mar 30, 2017 at 1:56
  • 1
    @Steve It's a suggested way to save a knowledge to answer your answers by yourself. Thats why SO has a Self-Learner badge Commented Mar 30, 2017 at 17:41

2 Answers 2

6
return StatusCode(402, responseObject);
return StatusCode(500, responseObject);
Sign up to request clarification or add additional context in comments.

Comments

2
Response.StatusCode = 500; // HttpStatusCode.
return responseObject;

OR

Response.StatusCode = StatusCodes.Status500InternalServerError; // HttpStatusCode.
return responseObject;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.