Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return on client error message with status code

I tried to use this:

return Request.CreateResponse(HttpStatusCode.InternalServerError, "My message");

also I tried this one:

return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, "My message");

But I see 500 error on my browser though any message like "My message" are displayed.

like image 938
Sergey Avatar asked Dec 26 '22 07:12

Sergey


1 Answers

To return a specific response code with a message from ASP.NET MVC controller use:

return new HttpStatusCodeResult(errorCode, "Message");

Make sure the method in the controller is type ActionResult, not ViewResult.

like image 91
Floremin Avatar answered Jan 07 '23 23:01

Floremin