| | |
| | | |
| | | namespace Utility |
| | | { |
| | | public class ApiResponseActionFilter: IAsyncActionFilter |
| | | public class ApiResponseActionFilter : IAsyncActionFilter |
| | | { |
| | | public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) |
| | | { |
| | |
| | | |
| | | await context.HttpContext.Response.WriteAsync(json); |
| | | } |
| | | if (resultContext.Result is EmptyResult) |
| | | { |
| | | var apiResponse = new ApiResponse<object>( |
| | | context.HttpContext.Response.StatusCode, |
| | | context.HttpContext.Response.StatusCode == 200 ? "请求成功" : "错误", |
| | | "请求成功" |
| | | ); |
| | | |
| | | var json = JsonConvert.SerializeObject(apiResponse); |
| | | context.HttpContext.Response.ContentType = "application/json"; |
| | | context.HttpContext.Response.ContentLength = Encoding.UTF8.GetByteCount(json); |
| | | |
| | | await context.HttpContext.Response.WriteAsync(json); |
| | | } |
| | | } |
| | | } |
| | | } |