1public class JsonErrorResult : JsonResult
2{
3 private readonly HttpStatusCode _statusCode;
4
5 public JsonErrorResult(object json) : this(json, HttpStatusCode.InternalServerError)
6 {
7 }
8
9 public JsonErrorResult(object json, HttpStatusCode statusCode) : base(json)
10 {
11 _statusCode = statusCode;
12 }
13
14 public override void ExecuteResult(ActionContext context)
15 {
16 context.HttpContext.Response.StatusCode = (int)_statusCode;
17 base.ExecuteResult(context);
18 }
19
20 public override Task ExecuteResultAsync(ActionContext context)
21 {
22 context.HttpContext.Response.StatusCode = (int)_statusCode;
23 return base.ExecuteResultAsync(context);
24 }
25}