Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

ASP.NET MVC returns Content-Type text/plain even if application/xml was requested in case of return type is string #3692

@YEVHENO

Description

@YEVHENO

This is my controller:

[Route("")]
public class ValuesController : Controller
{
    //This always returns text/plain
    [HttpPost("/text")]
    [Produces("application/xml", "application/json")]
    public string GetText() => "Some text";

    [HttpPost("/textarray")]
    [Produces("application/xml", "application/json")]
    public IEnumerable<string> GetTextarray() => new[] { "Some text", "Some text2" };
}

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

<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><string>Some text</string><string>Some text2</string></ArrayOfString>

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions