Skip to content

Instantly share code, notes, and snippets.

@sakapon
Last active March 27, 2018 06:37
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sakapon/672c985198737adf48f0b5aa03636779 to your computer and use it in GitHub Desktop.
AspNetWebApiSample/SampleWebApi/App_Start/WebApiConfig.cs
using System;
using System.Net.Http.Formatting;
using System.Web.Http;
using System.Web.Http.Cors;
namespace SampleWebApi
{
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
// CORS の有効化
config.EnableCors(new EnableCorsAttribute("*", "*", "*"));
// XML 形式は有効のまま。HTML が要求されたら JSON を返します。
config.Formatters.JsonFormatter.MediaTypeMappings.Add(new RequestHeaderMapping("Accept", "text/html", StringComparison.InvariantCultureIgnoreCase, true, "application/json"));
// XML 形式の無効化 その1
//config.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
// XML 形式の無効化 その2
//config.Formatters.Remove(config.Formatters.XmlFormatter);
// 以下略
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment