Last Updated: September 27, 2021
·
65.01K
· sebastianbusek

Return http status code in asp.net mvc

Sometimes I need just return http status code as response to XHR call in asp.net mvc and it's really annoying, at least for me, fast googling how to do it.

So, let me share my first and fast tip how to return http response codes.

int error = 500;
return new HttpStatusCodeResult(error);

Also you can use build in response class HttpNotFoundResult() and HttpUnauthorizedResult() as shortcut.

More about HttpStatusCodeResult you can find on MSDN and http status codes are available on Wikipedia.