C
C#5d ago
Jiry_XD

✅ Changing ASPNETCORE_ENVIRONMENT causes broken site.

Hi all, I am wanting to test our ASP .NET CORE App coupled with Blazor Wasm in production. So I changed ASPNETCORE_ENVIRONMENT to "Production", and altered Program.cs to work with it:
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();

using (var scope = app.Services.CreateScope())
{ // Require a DbContext from the service provider and seed the database.
var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
Seeder seeder = new(dbContext);
await seeder.Seed();
}
}
else
{
using (var scope = app.Services.CreateScope())
{ // Require a DbContext from the service provider and seed the database.
var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
Seeder seeder = new(dbContext);
await seeder.SeedProd();
}
}

app.UseHttpsRedirection();

app.UseBlazorFrameworkFiles();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();

app.MapControllers();
app.MapFallbackToFile("index.html");



app.Run();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();

using (var scope = app.Services.CreateScope())
{ // Require a DbContext from the service provider and seed the database.
var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
Seeder seeder = new(dbContext);
await seeder.Seed();
}
}
else
{
using (var scope = app.Services.CreateScope())
{ // Require a DbContext from the service provider and seed the database.
var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
Seeder seeder = new(dbContext);
await seeder.SeedProd();
}
}

app.UseHttpsRedirection();

app.UseBlazorFrameworkFiles();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();

app.MapControllers();
app.MapFallbackToFile("index.html");



app.Run();
Now I only get a white page and it is showing 3 warnings:
warn: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[16]
The WebRootPath was not found: MyPathHere Static files may be unavailable.
warn: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[16]
The WebRootPath was not found: MyPathHere Static files may be unavailable.
warn: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[16]
The WebRootPath was not found: MyPathHere Static files may be unavailable.
warn: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[16]
The WebRootPath was not found: MyPathHere Static files may be unavailable.
warn: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[16]
The WebRootPath was not found: MyPathHere Static files may be unavailable.
warn: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[16]
The WebRootPath was not found: MyPathHere Static files may be unavailable.
How can I fix this?
4 Replies
Tvde1
Tvde15d ago
Stack Overflow
When ASPNETCORE_ENVIRONMENT changed to anything but "Development" -...
Maybe just try the example: https://github.com/HTD/BlazorProfiles This is a demo Blazor application (default). I created 2 custom application profiles: Development and Production. Both should be
Jiry_XD
Jiry_XDOP5d ago
That fixed it Thanks What did you google for?
Tvde1
Tvde15d ago
Yay! I don't remember. Something like "blazor empty page ASPNETCORE_ENVIRONMENT"
Jiry_XD
Jiry_XDOP5d ago
Thanks 😛
Want results from more Discord servers?
Add your server