Skip to content

Blazor server - Static files from wwwroot doesn't load using IIS (404) #54216

Open
@lhidrovo

Description

@lhidrovo

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I Have a Blazor Server .NET 8 App. In my local environment using the name "Development" the application runs correctly. However, after hosting the application on an IIS server side, all the content references at wwwroot are returning 404 like CSS, images, and javascript files. It can't find any resources (wwroot) even though the folder does exist on the server. As additional information, the application is hosted by https://www.contoso.com/{MYAPP} and I have configured the App base path described in the documentation at App Base Path. Everything works in the dev environment, but no int the server.

Some code examples in the program file
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

builder.WebHost.UseWebRoot("wwwroot");
builder.WebHost.UseStaticWebAssets();

......

WebApplication app = builder.Build();

app.UseStaticFiles("/App/Treatment");
app.UsePathBase("/App/Treatment");

....
app.UseHttpsRedirection();

app.UseRouting();
app.UseCors();

app.UseAntiforgery();

app.UseCookiePolicy();
app.UseAuthentication();
app.UseAuthorization();
app.UseSession();
app.UseResponseCaching();

app.MapDefaultControllerRoute();

app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();

app.Run();

App.razor
<base href="/App/Treatment/" />

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

8.0.100

Anything else?

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsfeature-iisIncludes: IIS, ANCM

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions