I'm writing a webhook in asp.net core mvc where the caller posts some json. But the Content-Type is set to application/vnd.myget.webhooks.v1+json
. I just want to have this content type map to the JsonInputFormatter
.
I did this, but wondering if there is a better way:
services.AddMvc( mvcConfig =>
{
var formatter = new JsonInputFormatter();
formatter.SupportedMediaTypes.Add(
new MediaTypeHeaderValue("application/vnd.myget.webhooks.v1+json") );
mvcConfig.InputFormatters.Add( formatter );
});
You can modify the default InputFormatter
in ConfigureServices
services.Configure<MvcOptions>(options => {
options.InputFormatters.OfType<JsonInputFormatter>().First().SupportedMediaTypes.Add(
new MediaTypeHeaderValue("application/vnd.myget.webhooks.v1+json")
);
});
...perhaps a slight improvement
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With