-
Notifications
You must be signed in to change notification settings - Fork 2.1k
ASP.NET MVC returns Content-Type text/plain even if application/xml was requested in case of return type is string #3692
Comments
Have you added the |
Yes, I have added
In my controller |
I'd try adding the following to your startup code:
We have a formatter registered by default that treats strings as You could also bypass formatters if your content is already in the format you want.
|
Removing of |
My expectation was the following: Since I have marked method as |
We should figure out what we want to do with the StringFormatter. |
I would definitely suggest do not remove StringFormatter from OutputFormatters. Although, it partially solve my issue. |
discussed this with @lodejard and @kichalla today Thoughts that we had on the design tenets here:1. You should be able to return a string, and have it be whatever content type you want. This is for cases where you have pre-built XML or JSON or whatever.
2. You should be able to use formatters with setting response.ContentType
3. We feel kinda dubious about scenarios where you're using primitive/simple types with formatters....
|
My scenario for using primitive/simple types with formatters is the following: I have to interact with the system which expects text value as xml serialized string: |
Thanks, this is something we need to make sure stays working |
Load balancing to a different Ryan |
So @YEVHENO the end decision here ended up being that it was a bug that the content type was getting left as text/plain, but it is intended behavior that the string formatter takes the string before your xml formatter can get it. To get your desired behavior remove or re-arrange the StringOutputFormatter. |
This is my controller:
GetText() always returns text/plain even if I specify "Accept: application/xml" in request header. This happens only in case of return type "string". I expect get xml instead of plain text. See sample requests below:
Request 1:
GET /text HTTP/1.1
Host: localhost:5004
Accept: application/xml
Response 1:
HTTP/1.1 200 OK
Date: Fri, 04 Dec 2015 20:13:00 GMT
Content-Type: text/plain; charset=utf-8
Server: Kestrel
Some text
Request 2:
GET /textarray HTTP/1.1
Host: localhost:5004
Accept: application/xml
Response 2:
HTTP/1.1 200 OK
Date: Fri, 04 Dec 2015 20:13:04 GMT
Content-Type: application/json; charset=utf-8
Server: Kestrel
The text was updated successfully, but these errors were encountered: