Skip to content

Bad wwwroot path in Blazor 9 with ubuntu 24 and ProcessStartInfo #63295

@chouteau

Description

@chouteau

Unexpected behavior with Blazor Server and .NET 9 on Ubuntu 24

I have a service running on Ubuntu 24 that launches a Blazor web app via command line:

ProcessStartInfo dotnet MyWebApp.dll --urls "http://*:12345"

Like this

Image

Problem

All static assets return 404.

Service location: /opt/clustiis.host

Website location: /opt/wwwroot/proxiweb

The site tries to load its static assets from:

/opt/clustiis.host/wwwroot

instead of:

/opt/wwwroot/proxiweb/wwwroot

I find this behavior surprising.

Workaround

Manually configure the root directory location in Program.cs:

var entryAssembly = System.Reflection.Assembly.GetEntryAssembly();
var currentPath = Path.GetDirectoryName(entryAssembly!.Location)!;

app.UseStaticFiles(new StaticFileOptions
{
    FileProvider = new PhysicalFileProvider(System.IO.Path.Combine(currentPath, "wwwroot"))
});

Environment:

Ubuntu 24
.NET 9
Blazor Server

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresfeature-static-files

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions