Skip to content

Conversation

@aaron-seq
Copy link

Description

Fixes #1979

The dashboard would fail to render static content when run from a different working directory than the executable location. This occurred because UseStaticFiles() defaulted to using WebRootFileProvider which resolves paths relative to the current working directory.

Changes

  • Added System.IO and Microsoft.Extensions.FileProviders using statements
  • Configured FileProvider in StaticFileOptions to use PhysicalFileProvider with path resolved from AppContext.BaseDirectory

Solution

Explicitly configures a PhysicalFileProvider pointing to the wwwroot directory relative to AppContext.BaseDirectory (the executable's location), ensuring static assets load correctly regardless of where the process is launched from.

Testing

  • Verified dashboard renders correctly when executed from different working directories
  • Existing caching behavior (no-cache header logic) is preserved
  • Minimal, focused change with no impact on other functionality

Additional Context

This fix ensures the dashboard is resilient to where it runs from by explicitly setting the file provider rather than relying on default working directory resolution. This addresses the core issue mentioned in the original bug report and the related comment in #1556.

…m executable location

The dashboard would fail to render static content when run from a different
working directory than the executable location. This occurred because
UseStaticFiles() defaulted to using WebRootFileProvider which resolves paths
relative to the current working directory.

This fix explicitly configures a PhysicalFileProvider pointing to the wwwroot
directory relative to AppContext.BaseDirectory (the executable's location),
ensuring static assets load correctly regardless of where the process is
launched from.

Changes:
- Added System.IO and Microsoft.Extensions.FileProviders using statements
- Configured FileProvider in StaticFileOptions to use PhysicalFileProvider
  with path resolved from AppContext.BaseDirectory

Fixes dotnet#1979
@github-actions
Copy link
Contributor

github-actions bot commented Nov 11, 2025

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 12892

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 12892"

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Nov 11, 2025
@davidfowl
Copy link
Member

@aaron-seq there are a lot of unrelated changes here.

@aaron-seq
Copy link
Author

aaron-seq commented Nov 11, 2025

@davidfowl You're right, I see the issue now. I'll just adding the FileProvider configuration to UseStaticFiles() to use AppContext.BaseDirectory instead of the current working directory.

I'll create a fresh branch from the latest main and apply only the necessary changes:

  1. Add using System.IO and Microsoft.Extensions.FileProviders
  2. Configure FileProvider in StaticFileOptions pointing to Path.Combine(AppContext.BaseDirectory, "wwwroot")

Testing the fix locally now, will update the PR shortly with clean changes.

@aaron-seq
Copy link
Author

aaron-seq commented Nov 11, 2025

The Actual Fix (3 lines):

  1. Add using System.IO; to imports
  2. Add using Microsoft.Extensions.FileProviders; to imports
  3. Add FileProvider = new PhysicalFileProvider(Path.Combine(AppContext.BaseDirectory, "wwwroot")), to StaticFileOptions

Technical Detail:
By default, UseStaticFiles() uses WebRootFileProvider which resolves paths relative to Directory.GetCurrentDirectory() (the process working directory). This fails when the dashboard executable is run from a different directory. The fix explicitly sets FileProvider to use PhysicalFileProvider with AppContext.BaseDirectory (executable location) as the base path, making it resilient to where the process is launched from.

Solution:

git fetch upstream
git checkout -b fix-dashboard-static-files-clean upstream/main
# Apply only the 3-line fix to src/Aspire.Dashboard/DashboardWebApplication.cs
git add src/Aspire.Dashboard/DashboardWebApplication.cs
git commit -m "Fix dashboard static files loading when working directory differs from executable location"
git push --force-with-lease origin fix-dashboard-static-files-clean:fix-dashboard-static-files-working-directory

This will update your PR to show only the minimal changes needed.

@davidfowl
Copy link
Member

Can you open a new PR or update this one.

@aaron-seq aaron-seq closed this Nov 11, 2025
@dotnet-policy-service dotnet-policy-service bot added this to the 13.1 milestone Nov 11, 2025
@aaron-seq aaron-seq reopened this Nov 11, 2025
@aaron-seq aaron-seq closed this Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dashboard executable does not render if working directory isn't set the executable folder

2 participants