Hey,
It took me a few hours to work this out, so I wanted to write a post here in case someone else tries to do this and faces the same Issue.
It appears new ASP.NET Core applications, have dropped the web.config file, so the unity documentation can only get you halfway there.
Unity - Manual: WebGL: Server configuration code samples
From this MSDN page, I found out how to do it on Blazor.
I’m not sure if the settings will be different for the client-side build of Blazor. But here is the code for Server-Side. This is for a no compression build of WebGL, the compressed build setting can be found in the first link provided on the Unity documentation page. Just Edit accordingly.
Edit the Configure() function of the Startup.cs file like so:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
app.UseHsts();
}
app.UseHttpsRedirection();
// Remove This
// app.UseStaticFiles();
// Add This
var provider = new FileExtensionContentTypeProvider();
provider.Mappings.Remove(".data");
provider.Mappings[".data"] = "application/octet-stream";
provider.Mappings.Remove(".wasm");
provider.Mappings[".wasm"] = "application/wasm";
provider.Mappings.Remove(".symbols.json");
provider.Mappings[".symbols.json"] = "application/octet-stream";
app.UseStaticFiles(new StaticFileOptions { ContentTypeProvider = provider });
app.UseStaticFiles();
//--------------
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}
Happy Hunting 
3 Likes
Saved my life.
Just wanted to say that you can configure just one route to support this by doing this after app.UseEndpoints…
var provider = new FileExtensionContentTypeProvider();
provider.Mappings.Remove(".data");
provider.Mappings[".data"] = "application/octet-stream";
provider.Mappings.Remove(".wasm");
provider.Mappings[".wasm"] = "application/wasm";
provider.Mappings.Remove(".symbols.json");
provider.Mappings[".symbols.json"] = "application/octet-stream";
app.MapWhen(ctx => !ctx.Request.Path.StartsWithSegments("/_framework/BuildWebGL"),
subApp => subApp.UseStaticFiles(new StaticFileOptions() { ContentTypeProvider = provider }));
In this case it would only do it for the folder BuildWebGL inside wwwroot
2 Likes
I am struggling with this. I am using .net 6 on a new versions of Blazor server, there isn’t a Startup.cs. Presumably, these changes would go in Program.cs? When I place the BuildWebGL folder inside wwwroot I get a 404 server error.
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.StaticFiles;
using UnityBlazor.Data;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddSingleton<WeatherForecastService>();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
//app.UseStaticFiles();
var provider = new FileExtensionContentTypeProvider();
provider.Mappings.Remove(".data");
provider.Mappings[".data"] = "application/octet-stream";
provider.Mappings.Remove(".wasm");
provider.Mappings[".wasm"] = "application/wasm";
provider.Mappings.Remove(".symbols.json");
provider.Mappings[".symbols.json"] = "application/octet-stream";
app.MapWhen(ctx => !ctx.Request.Path.StartsWithSegments("/_framework/BuildWebGL"),
subApp => subApp.UseStaticFiles(new StaticFileOptions() { ContentTypeProvider = provider }));
app.UseRouting();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
app.Run();