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 123
The SPA default page middleware could not return the default page '/index.html' in production application hot 102
The SPA default page middleware could not return the default page '/index.html' in production application hot 96
Asp.Net MVC Core: “Error unprotecting the session cookie” exception hot 79
No DefaultChallengeScheme found from preview8 to preview9 hot 67
BadHttpRequestException: Reading the request body timed out due to data arriving too slowly hot 65
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 59
The library &#39;hostpolicy.dll&#39; required to execute the application was not found - AspNetCore hot 58
error CS1503: Argument 2: cannot convert from 'method group' to 'EventCallback' hot 57
Error: Invocation canceled due to the underlying connection being closed. hot 54
Unexpected end of request content k8s pod - AspNetCore hot 53
Using 'UseMvc' to configure MVC is not supported while using Endpoint Routing. To continue using 'UseMvc', please set 'MvcOptions.EnableEndpointRounting = false' inside 'ConfigureServices'. hot 50
IIS in-process hosting incorrectly throws ConnectionResetException for HTTP POST hot 47
HTTP Error 500.30 - ANCM In-Process Start Failure hot 43
Error: Server returned handshake error: Handshake was canceled. hot 43
Github User Rank List