'How to create a custom HTTP status code between 110 - 150 in action result?
I want to add a custom error code like 110, 108 with some message like "Invalid Id". Please suggest how to break the default HTTP status code in ASP.NET
Solution 1:[1]
Firstly you can't use 1xx range of HTTP status codes to show error.
1xx Informational
2xx Success
3xx Redirection
4xx Client Error
5xx Server Error
You can learn more about HTTP status codes here as well.
Secondly as you want to create custom code, I think this will answer your question How to show the status code with custom message in c#?
Solution 2:[2]
For example :
public ActionResult TestError(string id) // id = error code
{
Response.StatusCode = 400; // Replace .AddHeader
var error = new Error(); // Create class Error() w/ prop
error.ErrorID = 123;
error.Level = 2;
error.Message = "You broke the Internet!";
return Json(error, JsonRequestBehavior.AllowGet);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Maryam Yavarifard |
