using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Filters; using System; using System.Collections.Generic; using System.Linq; using System.Text.Json; using System.Threading.Tasks; using Ys.Core.Common; namespace djyweb_djyPaasApi { public class YsHttpResponseExceptionFilter : IActionFilter, IOrderedFilter { public int Order { get; } = int.MaxValue - 10; public void OnActionExecuted(ActionExecutedContext context) { var rs = new ReturnResult(); var response = context.HttpContext.Response; response.StatusCode = 200; response.WriteAsync(JsonSerializer.Serialize(rs, new JsonSerializerOptions(JsonSerializerDefaults.Web))).ConfigureAwait(false); } public void OnActionExecuting(ActionExecutingContext context) { var rs = new ReturnResult(); var response = context.HttpContext.Response; response.StatusCode = 200; response.WriteAsync(JsonSerializer.Serialize(rs, new JsonSerializerOptions(JsonSerializerDefaults.Web))).ConfigureAwait(false); } } }