Last active
March 27, 2018 06:37
Star
You must be signed in to star a gist
AspNetWebApiSample/SampleWebApi/App_Start/WebApiConfig.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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