修改返回头
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 }
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,12 +60,18 @@
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Web.ApplicationServices" />
|
||||
<Reference Include="System.Web.Cors, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.Cors.5.2.7\lib\net45\System.Web.Cors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.DynamicData" />
|
||||
<Reference Include="System.Web.Entity" />
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Web" />
|
||||
<Reference Include="System.Web.Abstractions" />
|
||||
<Reference Include="System.Web.Extensions" />
|
||||
<Reference Include="System.Web.Http.Cors, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.Cors.5.2.7\lib\net45\System.Web.Http.Cors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Web.Routing" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Configuration" />
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
<packages>
|
||||
<package id="Antlr" version="3.5.0.2" targetFramework="net45" />
|
||||
<package id="jQuery" version="3.4.1" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.Cors" version="5.2.7" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.Mvc" version="5.2.7" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.Mvc.zh-Hans" version="5.2.7" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.Razor" version="3.2.7" targetFramework="net45" />
|
||||
@@ -13,6 +14,7 @@
|
||||
<package id="Microsoft.AspNet.WebApi.Client.zh-Hans" version="5.2.7" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.7" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebApi.Core.zh-Hans" version="5.2.7" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebApi.Cors" version="5.2.7" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebApi.HelpPage" version="5.2.7" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.7" targetFramework="net45" />
|
||||
<package id="Microsoft.AspNet.WebApi.WebHost.zh-Hans" version="5.2.7" targetFramework="net45" />
|
||||
|
||||
Reference in New Issue
Block a user