Skip to content

Add CreateScopeForStatusCodePages to Blazor templates #62843

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 21, 2025

This PR adds UseStatusCodePagesWithReExecute with the createScopeForStatusCodePages parameter to the Blazor Web template, restoring functionality that was removed in PR #62624 due to CI issues with SDK versions.

Changes

Added a single line to the Blazor template's Program.cs file:

app.UseStatusCodePagesWithReExecute("/Error", createScopeForStatusCodePages: true);

Implementation Details

  • Location: Added in the non-development environment configuration block, after UseExceptionHandler and before UseHsts
  • Route: Uses the existing /Error page (same as the exception handler)
  • Parameter: Uses the new createScopeForStatusCodePages: true parameter name (renamed from the previous parameter)
  • Middleware Order: Follows ASP.NET Core pipeline conventions (exception handling → status code pages → security → protocol)

Verification

  • Template builds successfully without compilation errors
  • Only the BlazorWeb server template requires this change (BlazorWeb Client is WebAssembly-only)
  • No other project templates currently use StatusCodePages middleware
  • Change is minimal and surgical (single line addition)

The implementation enables proper service scope creation for status code page handling in Blazor applications, matching the pattern already used for exception handling with createScopeForErrors: true.

Fixes #62842.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copy link
Contributor

Greetings human! You've submitted a PR that modifies code that is shared with https://github.com/dotnet/runtime . Please make sure you synchronize this code with the changes in that repo!

@github-actions github-actions bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Jul 21, 2025
@ilonatommy ilonatommy added area-blazor Includes: Blazor, Razor Components and removed needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically labels Jul 21, 2025
@ilonatommy ilonatommy added this to the 10.0-rc1 milestone Jul 21, 2025
@Copilot Copilot AI changed the title [WIP] Add CreateScopeForStatusCodePages to blazor templates Add CreateScopeForStatusCodePages to Blazor templates Jul 21, 2025
@Copilot Copilot AI requested a review from ilonatommy July 21, 2025 15:35
Copilot finished work on behalf of ilonatommy July 21, 2025 15:35
@Copilot Copilot AI requested a review from ilonatommy July 22, 2025 07:59
Copilot finished work on behalf of ilonatommy July 22, 2025 07:59
@Copilot Copilot AI requested a review from ilonatommy July 22, 2025 08:07
Copilot finished work on behalf of ilonatommy July 22, 2025 08:07
@ilonatommy
Copy link
Member

the failure is #62851

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components Attention: Shared Code Modified
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add CreateScopeForStatusCodePages to blazor templates
2 participants