0

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 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I guess that this should work? But it isn't, and I can't figure out why.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.