dotnet / dotnet/aspnetcore

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

Open
#54,216 8 comments 2 reactions 0 assignees View on GitHub
area-middleware area-networking feature-iis
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] 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](https://learn.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/?view=aspnetcore-7.0&tabs=visual-studio#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()`
`.AddInteractiveServerRenderMode();`

`app.Run();`

**App.razor**
``

### Expected Behavior

_No response_

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version

8.0.100

### Anything else?

![image](https://github.com/dotnet/aspnetcore/assets/161242684/98363fac-fed3-4931-9cd4-3a01da6cd123)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.