Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

index.html default file not found when using UseDefaultFiles and MapStaticAssets (ASP.NET 9) #59399

Open
1 task done
tehmang opened this issue Dec 9, 2024 · 5 comments
Open
1 task done
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-static-web-assets

Comments

@tehmang
Copy link

tehmang commented Dec 9, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I'm currently learning ASP.NET Core.
From an empty .NET 9 Web application, I added a wwwroot folder with an index.html file.

In Program.cs, I used UseDefaultFiles and MapStaticAssets as follows :

app.UseHttpsRedirection();
app.UseDefaultFiles();
//comment the line 13 and uncomment line 14 to make it work
app.MapStaticAssets();
//app.UseStaticFiles();

Expected Behavior

The expected behavior is simply to see my index.html page rendered by the brower.

Steps To Reproduce

Github repo with the simpliest sln to reproduce the issue: MapStaticAssets-issue

Exceptions (if any)

No response

.NET Version

9.0.101

Anything else?

VS 2022 17.12.3

dotnet --info:
SDK .NET :
Version: 9.0.101
Commit: eedb237549
Workload version: 9.0.100-manifests.4a280210
MSBuild version: 17.12.12+1cce77968

Environnement d'exécution :
OS Name: Windows
OS Version: 10.0.26100
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\9.0.101\

Charges de travail .NET installées :
[android]
Source de l’installation: VS 17.12.35527.113
Version de manifeste: 35.0.7/9.0.100
Chemin d'accès au Manifeste: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.android\35.0.7\WorkloadManifest.json
Type d'installation: Msi

[aspire]
Source de l’installation: VS 17.12.35527.113
Version de manifeste: 8.2.2/8.0.100
Chemin d'accès au Manifeste: C:\Program Files\dotnet\sdk-manifests\8.0.100\microsoft.net.sdk.aspire\8.2.2\WorkloadManifest.json
Type d'installation: Msi

[maui-windows]
Source de l’installation: VS 17.12.35527.113
Version de manifeste: 9.0.0/9.0.100
Chemin d'accès au Manifeste: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maui\9.0.0\WorkloadManifest.json
Type d'installation: Msi

[maccatalyst]
Source de l’installation: VS 17.12.35527.113
Version de manifeste: 18.1.9163/9.0.100
Chemin d'accès au Manifeste: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.maccatalyst\18.1.9163\WorkloadManifest.json
Type d'installation: Msi

[ios]
Source de l’installation: VS 17.12.35527.113
Version de manifeste: 18.1.9163/9.0.100
Chemin d'accès au Manifeste: C:\Program Files\dotnet\sdk-manifests\9.0.100\microsoft.net.sdk.ios\18.1.9163\WorkloadManifest.json
Type d'installation: Msi

Configuré pour utiliser loose manifests lors de l’installation de nouveaux manifestes.

Host:
Version: 9.0.0
Architecture: x64
Commit: 9d5a6a9aa4

.NET SDKs installed:
9.0.101 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework label Dec 9, 2024
@tehmang tehmang changed the title index.html default file not found when using UseDefaultFiles and MapStaticAssets index.html default file not found when using UseDefaultFiles and MapStaticAssets (ASP.NET 9) Dec 9, 2024
@gfoidl gfoidl added feature-static-web-assets area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-infrastructure Includes: MSBuild projects/targets, build scripts, CI, Installers and shared framework labels Dec 10, 2024
@luka-kusulja
Copy link

don't use app.MapStaticAssets();
use this instead app.UseStaticFiles();

@SaebAmini
Copy link

SaebAmini commented Dec 11, 2024

Since MapStaticAssets is being pushed as the new optimised alternative, this needs to be resolved. Seeing the same issue.

@peterwurzinger
Copy link

don't use app.MapStaticAssets(); use this instead app.UseStaticFiles();

Yeah, I mean, one wouldn't even need an expensive ASP.NET Core Host to serve static HTML only anyways, the point of all that is, that serving of application assets should be optimized. UseStaticFiles essentially excludes projects that e.g. use some kind of static index.html one-pager as entrypoint for an MVC application from those optimizations.

I faced the same issue today and to me it rather seems that it is a problem with Hot Reload than with the middleware itself. Disabling Hot Reload in Visual Studio did fix the issue and the static index.html was served without errors. So to verify that:

  • dotnet run works (both with -c Release and -c Debug)
  • dotnet publish works (both with -c Release and -c Debug)
  • Being started within Visual Studio with Hot Reload enabled brings up the Content Encoding error @tehmang described
  • Being started within Visual Studio with Hot Reload disabled fixes the issue
  • Being started with dotnet watch brings up the Content Encoding error

So the issue likely is a combination of Hot Reload with MapStaticAssets()

@SaebAmini
Copy link

This happens on a deployment environment so I doubt it’d just be a hot reload issue.

@peterwurzinger
Copy link

Oh alright, I only saw the issue on my local machine for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc feature-static-web-assets
Projects
None yet
Development

No branches or pull requests

5 participants