This question is almost verbatim what is being asked on this stackoverflow question
But I'd like to do it in a ASP.NET Core Api. I'm planning on implementing it as a a header instead of in the query string. I'm struggling with changing the Json SerializerSettings that has been set in the ConfigureServices method.
services.AddMvc(config =>
{
config.Filters.Add(new WebApiRequireHttps());
})
.AddJsonOptions(options =>
{
options.SerializerSettings.Formatting = Formatting.Indented;
});
What I'm trying to accomplish is change the Serializer's settings to use Formatting.None when I've set a header like X-MyApi-Pretty: false.
I'm trying to create my own ActionFIlterAttribute like in the aforementioned question. Microsoft.AspNetCore.Mvc.Filters uses ActionExecutedContext which doesn't seem to have an obvious equivalent to ActionContext.RequestContext.Configuration.Formatters.JsonFormatter.
Is there an equivalent or am I just going about this all wrong? My google-fu is really failing me on this and I feel like I'm missing something really obvious.