dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.61k stars 10.07k forks source link

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

Open danroth27 opened 3 weeks ago

danroth27 commented 3 weeks ago

Repro steps:

<!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:

fingers10 commented 2 weeks ago

@danroth27 I'm facing same issue in blazor wasm standalone app. I upgraded my .net8 blazor wasm standalone app to .net9. The app has authentication setup using oauth and openidconnect. Entire blazor wasm is under authorisation. So when the index.html load usually it wil redirect to identity provider to challenge user. This was working in .net8. But after upgrading to .net9 and when I do dotnet watch run, I see the below blank page.

Image

Meanwhile in terminal,

Image

When I manually navigate to any URL in my blazor wasm app, it loads the page. But i can see the below error in console

Image

And if I click refresh button in browser, I again see the below blank page

Image

Now I need to press ctrl + c in terminal and that throws the following error

dotnet watch 🛑 Shutdown requested. Press Ctrl+C again to force exit.
dotnet watch ❌ System.FormatException: Input string was not in a correct format. Failure to parse near offset 115. Expected an ASCII digit.
   at System.Text.ValueStringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ReadOnlySpan`1 args)
   at System.String.FormatHelper(IFormatProvider provider, String format, ReadOnlySpan`1 args)
   at System.String.Format(String format, Object[] args)
   at Microsoft.Extensions.Tools.Internal.MessageDescriptor.TryGetMessage(String prefix, Object[] args, String& message)
   at Microsoft.Extensions.Tools.Internal.ConsoleReporter.Report(MessageDescriptor descriptor, String prefix, Object[] args)
   at Microsoft.Extensions.Tools.Internal.IReporter.Report(MessageDescriptor descriptor, Object[] args)
   at Microsoft.Extensions.Tools.Internal.IReporter.Verbose(String message, String emoji)
   at Microsoft.DotNet.Watcher.Tools.IncrementalMSBuildWorkspace.<>c__DisplayClass6_0.<<ReportSolutionFilesAsync>g__InspectDocumentAsync|0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.DotNet.Watcher.Tools.IncrementalMSBuildWorkspace.ReportSolutionFilesAsync(Solution solution, CancellationToken cancellationToken)
   at Microsoft.DotNet.Watcher.Tools.IncrementalMSBuildWorkspace.UpdateProjectConeAsync(String rootProjectPath, CancellationToken cancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.Program.RunAsync()
dotnet watch ❌ An unexpected error occurred

Again I need to dotnet watch run and index.html will be blank with Failed to load resource: net::ERR_CONTENT_DECODING_FAILED error in console and i need manually navigate to any page by changing url in browser and if I try to log out I again see the below error. Calls getting cancelled in network tab.

Image

Now If I rollback to .net8 still the issue persist. net9 installation broke something.

I tested this in VS Code in Mac OS sequoia 15.1 and also in Visual Studio in windows 11. Facing same issue in both machines. Looks like local development is blocked because of this.

I notice this behavior only in development mode. I tried to publish and run in IIS and I dont see any issue.

peterthorpe81 commented 2 weeks ago

I also have this issue, changing the file extension results in the wrong mime type sent to the browser so doesn't work for my use case.

A potential alternative workaround is creating a different static directory for your html files. Then use MapStaticAssets alongside:

app.UseStaticFiles(new StaticFileOptions
{
    FileProvider = new PhysicalFileProvider(
        Path.Combine(builder.Environment.ContentRootPath, "Static")),
    RequestPath = "/Static"
});

I am assuming its valid to use both if UseStaticFiles is set to an alternative directory.

space-alien commented 1 week ago

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.

fingers10 commented 1 week ago

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>

This file is seemingly served correctly.

Broken:

<!DOCTYPE HTML>

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.

Hope this helps.

by default blazor wasm apps will serve index.html file and is that why my blazor wasm apps are not getting served? @danroth27 any helps?