I'm writing a WebAPI application and trying to remove XML. I have removed the XmlFormatter but if I make a request with Accept: application/xml I still get a 200 response with an application/json body. Why is this? How do I ensure that I get back a 406 error instead?
1 Answer
WebAPI desperately want to return a response, so the default content negotiator falls back to the one available when no match was found.
You'll have to provide excludeMatchOnTypeOnly:
var negotiator = new DefaultContentNegotiator(excludeMatchOnTypeOnly: true);
config.Services.Replace(typeof(IContentNegotiator), negotiator);
At least, according to this 2012 blog post.
1 Comment
coppro
I guess that this should work? But it isn't, and I can't figure out why.