修改返回头
This commit is contained in:
@@ -10,6 +10,7 @@ using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Http;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Cors;
|
||||
using System.Web.Http.Filters;
|
||||
|
||||
namespace NX.ERP.WebAPi
|
||||
@@ -48,7 +49,7 @@ namespace NX.ERP.WebAPi
|
||||
//请求是否成功
|
||||
// result.IsSuccess = actionExecutedContext.ActionContext.Response.IsSuccessStatusCode;
|
||||
//结果转为自定义消息格式
|
||||
HttpResponseMessage httpResponseMessage = new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(result, GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings)) };
|
||||
HttpResponseMessage httpResponseMessage = new HttpResponseMessage() { Content = new ObjectContent<ResultModel<object>>(result, new JsonMediaTypeFormatter()) };
|
||||
// 重新封装回传格式
|
||||
actionExecutedContext.Response = httpResponseMessage;
|
||||
}
|
||||
@@ -88,7 +89,8 @@ namespace NX.ERP.WebAPi
|
||||
{
|
||||
//忽略循环引用,如果设置为Error,则遇到循环引用的时候报错
|
||||
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
|
||||
Formatting = Newtonsoft.Json.Formatting.Indented,
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
//Formatting = Newtonsoft.Json.Formatting.Indented,
|
||||
//小驼峰命名法
|
||||
//ContractResolver = new DefaultContractResolver()
|
||||
//{
|
||||
@@ -101,7 +103,7 @@ namespace NX.ERP.WebAPi
|
||||
//NullValueHandling = NullValueHandling.Ignore
|
||||
|
||||
};
|
||||
|
||||
config.EnableCors(new EnableCorsAttribute("*", "*", "*"));
|
||||
|
||||
// Web API 路由
|
||||
config.MapHttpAttributeRoutes();
|
||||
@@ -111,6 +113,7 @@ namespace NX.ERP.WebAPi
|
||||
routeTemplate: "api/{controller}/{action}/{code}",
|
||||
defaults: new { code = RouteParameter.Optional }
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user