From a391f3d35818acb736bfaab1b1e2138694eb50ab Mon Sep 17 00:00:00 2001 From: xxred Date: Tue, 6 Nov 2018 17:33:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=AA=8C=E7=AD=BE=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=BA=94=E7=94=A8=E7=A8=8B=E5=BA=8F=E5=87=BA=E9=94=99?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- COMCMS.Web/Filter/CheckFilter.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/COMCMS.Web/Filter/CheckFilter.cs b/COMCMS.Web/Filter/CheckFilter.cs index ded9ebb..70cd663 100644 --- a/COMCMS.Web/Filter/CheckFilter.cs +++ b/COMCMS.Web/Filter/CheckFilter.cs @@ -6,6 +6,7 @@ using COMCMS.Common; using COMCMS.Web.Common; using COMCMS.Web.Controllers.api; using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Filters; @@ -39,7 +40,12 @@ namespace COMCMS.Web.Filter if (notVali != null) { - await context.HttpContext.Response.WriteAsync(notVali.ToJson()); + // 过滤器不要抛出错误,也不要向响应流写东西,应该直接赋值Result进行短路 + context.Result = new ContentResult() + { + Content = notVali.ToJson(), + ContentType = "application/json" + }; } }