Ask questionsUseStaticFiles with StaticFileOptions/FileExtensionContentTypeProvider breaks server side Blazor

Describe the bug

Passing StaticFileOptions with a FileExtensionContentTypeProvider to app.UseStaticFiles breaks Blazor

To Reproduce

dotnet new blazorserverside edit startup.cs, replacing app.UseStaticFiles(); with the following ...

var provider = new FileExtensionContentTypeProvider(); provider.Mappings.Add(".appx", "application/octet-stream"); app.UseStaticFiles(new StaticFileOptions() { ContentTypeProvider = provider });

Expected behavior

Blazor works

Error message

info: Microsoft.AspNetCore.Hosting.Internal.GenericWebHostService[1] Request starting HTTP/2 GET https://localhost:5001/_framework/blazor.server.js info: Microsoft.AspNetCore.Hosting.Internal.GenericWebHostService[2] Request finished in 2.66ms 404

dotnet version

dotnet --info .NET Core SDK (reflecting any global.json): Version: 3.0.100-preview4-011223 Commit: 118dd862c8

Runtime Environment: OS Name: Windows OS Version: 10.0.17763 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.0.100-preview4-011223\

Host (useful for support): Version: 3.0.0-preview4-27615-11 Commit: ee54d4cbd2

.NET Core SDKs installed: 2.1.600 [C:\Program Files\dotnet\sdk] 2.1.601 [C:\Program Files\dotnet\sdk] 2.1.602 [C:\Program Files\dotnet\sdk] 2.1.700-preview-009597 [C:\Program Files\dotnet\sdk] 3.0.100-preview4-011223 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0-preview-19075-0444 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0-preview3-19153-02 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0-preview4-19216-03 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0-preview-27324-5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0-preview3-27503-5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0-preview4-27615-11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.0-preview4-27613-28 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:


Answer questions javiercn

This is fixed for static assets comming out of RCL, but I fear that this is by design for blazor-server side as it brings in an embedded file and to do so it configures the options for the static files middleware. If you use your own options then it misconfigures blazor server-side.

The alternatives are:

  • Configure options though DI, using services.Configure<StaticFileOptions>(...)
  • Add two calls to app.UseStaticFiles one with your options before and another one like app.UseStaticFiles() later.
    • All content but blazor.server.js will be served with your options.

@rynowak @SteveSandersonMS in case we want to reconsider not shipping blazor.server.js as an embedded file, as the reasons against it keep stacking up.


Related questions

HTTP Error 500.31 - ANCM Failed to Find Native Dependencies hot 8
MissingMethodException: Method not found Microsoft.EntityFrameworkCore.Metadata.Builders.IndexBuilder
Migrate Asp.Net Core 2.2 Integration Tests to 3.0 - The TestServer constructor was not called with a IWebHostBuilder so IWebHost is not available. hot 4
SignalR .NetCore 3.0-- HubConnectionBuilder' does not contain a definition for 'WithUrl' hot 3
HTTP Error 500.30 - ANCM In-Process Start Failure hot 3
With core 3.0 SignInManager.IsSignedIn(User) allways reuturn false?but in 2.2 it works fine.Is that a debug? hot 3
CSS Isolation in Blazor Components hot 3
How to retrieve the HttpContext from Blazor server-side ? hot 3
Oauth2 authentication erroring with "The oauth state was missing or invalid." hot 3
Failed to gracefully shutdown application (IIS Hang) hot 3
BadHttpRequestException: Reading the request body timed out due to data arriving too slowly hot 2
HTTP Error 500.0 - ANCM In-Process Handler Load Failure hot 2
Method not found: 'Microsoft.EntityFrameworkCore.Metadata.Builders.IndexBuilder Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder`1.HasIndex(System.Linq.Expressions.Expression`1<System.Func`2<System.__Canon,System.Object>>)'. hot 2
MissingMethodException at SignInManager ctor after update hot 2
Github User Rank List