I'm attempting to host a WASM application on my machine (eventually, I want to service it using a Windows Service).
My test is very straightforward:
- Create a Blazor standalone app (with some demo pages)
- Publish it
- Create an empty ASP NET Core project (the project that will host/service the app)
- Configure it to service static files
- Copy published wwwroot into wwwroot of the host project
The only code changes, I did in the program.cs of the host project:
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.UseStaticFiles();
app.MapFallbackToFile("index.html");
app.Run();
Now i'm getting error "Failed to load resource: the server responded with a status of 404 ()" for file "https://localhost:7199/_framework/icudt_EFIGS.tptq2av103.dat"
When i'm trying to access other files, e.g. "https://localhost:7199/favicon.png" it is working, so some files are getting served.
I've checked and the file "_framework/icudt_EFIGS.tptq2av103.dat" does exist in the wwwroot directory.
It's probably some small configuration I'm missing, but I (and chatGPT) can't figure it out.
The end goal is to publish the host and then run it as a Windows Service. This means Kestrel is used, NOT iis.
I'm attempting to host a WASM application on my machine (eventually, I want to service it using a Windows Service).
My test is very straightforward:
- Create a Blazor standalone app (with some demo pages)
- Publish it
- Create an empty ASP NET Core project (the project that will host/service the app)
- Configure it to service static files
- Copy published wwwroot into wwwroot of the host project
The only code changes, I did in the program.cs of the host project:
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.UseStaticFiles();
app.MapFallbackToFile("index.html");
app.Run();
Now i'm getting error "Failed to load resource: the server responded with a status of 404 ()" for file "https://localhost:7199/_framework/icudt_EFIGS.tptq2av103.dat"
When i'm trying to access other files, e.g. "https://localhost:7199/favicon.png" it is working, so some files are getting served.
I've checked and the file "_framework/icudt_EFIGS.tptq2av103.dat" does exist in the wwwroot directory.
It's probably some small configuration I'm missing, but I (and chatGPT) can't figure it out.
The end goal is to publish the host and then run it as a Windows Service. This means Kestrel is used, NOT iis.
Share Improve this question edited Mar 29 at 15:33 Jasper asked Mar 20 at 8:13 JasperJasper 1691 silver badge12 bronze badges 4- why not just publish the 1st project, and delete the 2nd? but to get the 2nd to work all your static files should be in the special "wwwroot" folder. (right-click on that folder, it has a globe icon, choose, Add>Existing Item, and select your built files. You'll need to add that "_framework" folder there. Then you probably want: app.UseDefaultFiles(); app.UseStaticFiles(new StaticFileOptions() { FileProvider = new PhysicalFileProvider( Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot")) }); In program.cs. – browsermator Commented Mar 20 at 19:38
- The reason for this setup is that I want to host the WASM as a Windows service on a server. As it will only be used on one location, IIS would be overkill. As stated in the question, I already set it up like you suggested. Please have a look at the repos for reference. I tried your code suggestions, they did not change the result. – Jasper Commented Mar 21 at 10:23
- I think the problem is that it's trying to load _framework files relative to where the executable runs. So it doesn't know to reference "wwwroot/_framework..." Not real sure how to fix that. I suppose you could try manually copying that directory up one level after you publish. – browsermator Commented Mar 21 at 16:39
- I tried that, but even going to the file path in the browser directly resulted in a 404. I did find the solution though, will post it as an answer to my own question. – Jasper Commented Mar 23 at 10:00
1 Answer
Reset to default 0The solution was setting ServeUnknownFileTypes
to true
, like so:
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.UseStaticFiles(new StaticFileOptions {ServeUnknownFileTypes = true});
app.MapFallbackToFile("index.html");
app.Run();