aspnetcore: Returning HTML using Produces("text/html") causes 406 response
After upgrading to ASP.NET Core 2.0, [Produces("text/html")] doesn’t seem to work anymore. I am returning a string in my action using Ok(str) with that attribute specified.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 18 (12 by maintainers)
The
StringOutputFormatterused to ignore content types entirely and it no longer does this - it will only outputtext/plain. If you want it to output strings astext/htmlthen you can add that as well.Personally I would just use
Content(...)for this. You have the HTML text, and the content type already decided. This doesn’t rely on serialization nor on content negotiation.Yeah. The docs seem to support this.
I’ve added this for now: