title: Returning generated HTML from .NET Core controller
body: <p>I have a .NET Core 2 app that needs to be able to return generated HTML from a controller. I've been able to get it returning the HTML as plain text, but not to persuade the browser that it's HTML and render that; as soon as an HTML content type is provided, the content type negotiation appears to break it and it just renders a 406 Not Acceptable.</p>
  <p>(Simplified) options I've tried -</p>
  <pre><code>    [HttpGet]
      [Produces(&quot;text/html&quot;)]
      public string Display()
      {
          return &quot;&lt;html&gt;&lt;head&gt;&lt;title&gt;Testing&lt;/title&gt;&lt;head&gt;&lt;body&gt;Hello, world!&lt;/body&gt;&lt;/html&gt;&quot;;
      }
  
      [HttpGet]
      [Produces(&quot;text/html&quot;)]
      public HttpResponseMessage Display()
      {
          try
          {
              var response = new HttpResponseMessage(HttpStatusCode.OK)
              {
                  Content = new StringContent(&quot;&lt;html&gt;&lt;head&gt;&lt;title&gt;Testing&lt;/title&gt;&lt;head&gt;&lt;body&gt;Hello, world!&lt;/body&gt;&lt;/html&gt;&quot;)
              };
              response.Content.Headers.ContentType = new MediaTypeHeaderValue(&quot;text/html&quot;);
  
              return response;
          }
          catch (Exception ex)
          {
              Debug.WriteLine(ex.Message);
              return new HttpResponseMessage(HttpStatusCode.InternalServerError);
          }
      }
  
      [HttpGet]
      [Produces(&quot;text/html&quot;)]
      public IActionResult Display()
      {
          var pageHtml = &quot;&lt;html&gt;&lt;head&gt;&lt;title&gt;Testing&lt;/title&gt;&lt;head&gt;&lt;body&gt;Hello, world!&lt;/body&gt;&lt;/html&gt;&quot;;
          var result = StatusCode(200, pageHtml);
          result.ContentTypes.Add(new MediaTypeHeaderValue(&quot;text/html&quot;));
  
          return StatusCode(200, pageHtml);
      }
  </code></pre>
  <p>The <code>Startup.ConfigureServices</code> method has been tried with all combinations I can think of of the <code>RespectBrowserAcceptHeader</code> and <code>ReturnHttpNotAcceptable</code> properties, but they didn't seem to make a difference.</p>
  <p>Can anyone see what I've missed to persuade the server to just return the generated HTML?</p>