Skip to content

Basic UTF-8 encoded html pages served through UseStaticFiles don't have their ContentType charset correctly set #4546

@Abarbz

Description

@Abarbz

Description

When serving static utf-8 encoded html pages with Asp.Net Core's UseStaticFiles, the response ContentType is set to text/html and not text/html; charset=utf-8

To Reproduce

Steps to reproduce the behavior:

  1. Using ASP.NET Core v2.1.0, create a new Web API project, and disable IIS integration.
  2. Add .UseDefaultFiles().UseStaticFiles() to Startup.Configure()
  3. Create an html page named default.html in wwwroot and containing the following html fragment:
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8" />
    <title>My page title</title>
</head>

<!--Some static content-->

</html>
  1. Run the project and use postman or equivalent to GET the default url http://localhost:61106/
  2. Check the response header. It shows Content-Type →text/html

Expected behavior

Content-Type should be text/html; charset=utf-8 (or whatever charset is declared in the html page).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions