_The preceding [Produces] filter:
Forces all actions within the controller to return JSON-formatted responses._
As per my tests, it doesn't. The "About" action as coded on this page will still return text/plain content.
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
That's because the About action is returning Razor, unlike a Web API.
Apply [Produces("text/plain")] to the weather controller, and it returns a 406
Perhaps if it's not able to convert to JSON, it returns the default.
cc @serpent5
Well if the filter under certain condition forces a result format while under other conditions it doesn't, and it's not clear what these conditions are, I wouldn't feel confident using it!
The About action uses Content, which is described in this topic as specifying a text/plain response:
To return plain text formatted data, use
ContentResultand theContenthelper
Produces only really applies to ObjectResult. The scaffolded WeatherForecastController has a single Get action, which ends up using ObjectResult. If it were to use Content, or return a string, it would override the [Produces] attribute and return a text/plain response.
OK, thanks, that's a good explanation, and what's missing in the doc!
@serpent5 do you want this one?
@Rick-Anderson Sure, but feel free to pick it up if you get time before I do.
Most helpful comment
The
Aboutaction usesContent, which is described in this topic as specifying a text/plain response:Producesonly really applies toObjectResult. The scaffoldedWeatherForecastControllerhas a singleGetaction, which ends up usingObjectResult. If it were to useContent, or return astring, it would override the[Produces]attribute and return a text/plain response.