43 lines
1.4 KiB
C#
43 lines
1.4 KiB
C#
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Serialization;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Http;
|
|
using System.Web.Http.Controllers;
|
|
|
|
namespace KJD_Web
|
|
{
|
|
public static class WebApiConfig
|
|
{
|
|
public static void Register(HttpConfiguration config)
|
|
{
|
|
// 让 AsmxApiController 的所有 Action 同时支持 GET 和 POST
|
|
config.Services.Replace(typeof(IHttpActionSelector), new GetPostActionSelector());
|
|
|
|
// 特性路由:你 ImageCacheController 上的 [Route] 依赖这个
|
|
config.MapHttpAttributeRoutes();
|
|
|
|
// 默认路由
|
|
config.Routes.MapHttpRoute(
|
|
name: "DefaultApi",
|
|
routeTemplate: "{controller}/{action}/{id}",
|
|
defaults: new { id = RouteParameter.Optional }
|
|
);
|
|
|
|
var jsonFormatter = config.Formatters.JsonFormatter;
|
|
jsonFormatter.SerializerSettings.ContractResolver =
|
|
new CamelCasePropertyNamesContractResolver();
|
|
jsonFormatter.SerializerSettings.DateFormatHandling = DateFormatHandling.IsoDateFormat;
|
|
//jsonFormatter.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
|
|
jsonFormatter.SerializerSettings.Formatting = Formatting.None;
|
|
|
|
//config.Filters.Add(new SignValidateFilterAttribute());
|
|
config.Formatters.Remove(config.Formatters.XmlFormatter);
|
|
config.Filters.Add(new NotFoundMessageFilter());
|
|
config.MessageHandlers.Add(new NotFoundMessageHandler());
|
|
|
|
}
|
|
}
|
|
} |