I\'m trying to set the global serializer settings like this in my global.asax.
var formatter = GlobalConfiguration.Configuration.Formatters.Json
You're correct about where to set the serializer. However, that serializer is used when the request to your site is made with a requested content type of JSON. It isn't part of the settings used when calling SerializeObject. You could work around this by exposing the JSON serialization settings defined global.asax via a property.
public static JsonSerializerSettings JsonSerializerSettings
{
get
{
return GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings;
}
}
And then use this property to set the serialization settings when doing serialization within your controllers:
return new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(JsonConvert.SerializeObject(page, WebApiApplication.JsonSerializerSettings))
};