aspnetcore: Error when loading test.html using MapStaticAssets: Failed to load resource: net::ERR_CONTENT_DECODING_FAILED

Repro steps:

  • Create an empty ASP.NET Core app
  • Add app.MapStaticAssets()
  • Add wwwroot/test.html
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <h1>Test</h1>
</body>
</html>

Run the app and browser to /test.html

Expected result: test.html renders in the browser

Actual result: Failed to load resource: net::ERR_CONTENT_DECODING_FAILED

Workarounds:

  • Swap app.MapStaticAssets() for app.UseStaticFiles()
  • Use a .json file instead of a .html file

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 14
  • Comments: 21 (7 by maintainers)

Most upvoted comments

This is a pain.

I have found that the presence of a <body> tag within the html file somehow breaks the serving of the file.

OK:

<!DOCTYPE HTML>

<html>

This file is seemingly served correctly.

</html>

Broken:

<!DOCTYPE HTML>

<html>

<body>
    This file won't render in the browser. Dev tools report "Failed to load
    response data: No data found for resource with given identifier".
    Yum.
</body>

</html>

Hope this helps.

Setting "ReloadStaticAssetsAtRuntime": "false" should workaround the issue.

@danroth27 @javiercn I’m facing this issue with standalone blazor wasm app. Where should I add this setting in blazor wasm standalone app?

In lauchSettings.json

Anyway, it seems the issue is due to gzip compression of static assets collides with browser link. You can stop hot reload by adding the following line in launchSettings.json “hotReloadEnabled”: false

"https": { "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", "applicationUrl": "https://localhost:5032", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, "hotReloadEnabled": false },

@javiercn Will we be fixing this in a patch?