Skip to content

Add CreateScopeForStatusCodePages property and UseStatusCodePagesWithReExecute overload #62624

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 9, 2025

This PR implements the approved API proposal to add support for creating DI scopes when re-executing requests in StatusCodePages middleware.

Changes Made

API Surface Changes

StatusCodePagesOptions:

  • Renamed CreateScopeForErrorsCreateScopeForStatusCodePages property
  • Property defaults to false to maintain existing behavior

StatusCodePagesExtensions:

  • Modified existing UseStatusCodePagesWithReExecute(string, string?) to remove default parameter
  • Added new overload: UseStatusCodePagesWithReExecute(string, string? = null, bool createScopeForStatusCodePages = false)

Usage Examples

// Default behavior (no scope creation)
app.UseStatusCodePagesWithReExecute("/error/{0}");

// With scope creation enabled
app.UseStatusCodePagesWithReExecute("/error/{0}", createScopeForStatusCodePages: true);

// With query format and scope creation
app.UseStatusCodePagesWithReExecute("/error/{0}", "?code={0}", createScopeForStatusCodePages: true);

Implementation Details

  • Updated internal CreateHandler method to use the new property name
  • Added comprehensive tests to verify the new functionality
  • Updated PublicAPI files to reflect the API changes
  • Maintained backward compatibility

Benefits

This change allows error handling middleware to run in a fresh DI scope, which is important for scenarios where:

  • Scoped services should not be shared between the original and re-executed requests
  • Error handling requires isolated service state
  • Similar to the existing CreateScopeForErrors functionality in ExceptionHandler

The API follows the same pattern as ExceptionHandlerOptions.CreateScopeForErrors for consistency.

Fixes #62408.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

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!

@ilonatommy
Copy link
Member

@copilot I updated the description. Make your updates based on the required updates listed there.

… new overload

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Api proposal for UseStatusCodePagesWithReExecute Add CreateScopeForStatusCodePages property and UseStatusCodePagesWithReExecute overload Jul 9, 2025
@Copilot Copilot AI requested a review from ilonatommy July 9, 2025 07:37
Copilot finished work on behalf of ilonatommy July 9, 2025 07:37
Copy link
Contributor Author

Copilot AI commented Jul 9, 2025

@copilot I updated the description. Make your updates based on the required updates listed there.

My implementation already aligns with the updated description requirements. The changes include:

✅ Renamed CreateScopeForErrorsCreateScopeForStatusCodePages property
✅ Modified existing method to remove default parameter
✅ Added new overload with correct parameter order and defaults
✅ Updated PublicAPI files accordingly
✅ All usage examples work as specified

Build and tests pass successfully. (b6bec12)

@Copilot Copilot AI requested a review from ilonatommy July 9, 2025 07:47
Copilot finished work on behalf of ilonatommy July 9, 2025 07:47
Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Copilot finished work on behalf of ilonatommy July 9, 2025 07:59
Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Copilot finished work on behalf of ilonatommy July 9, 2025 08:26
@ilonatommy
Copy link
Member

ilonatommy commented Jul 9, 2025

@halter73, removing optionality in the old method, following the guidelines of roslyn, requires a change to Shipped.txt. Is that all right in the current release phase?

Detected modification to baseline API files. PublicAPI.Shipped.txt files should only be updated after a major release, and PublicAPI.Unshipped.txt files should not be updated in release branches.

@ilonatommy ilonatommy marked this pull request as ready for review July 9, 2025 10:32
@ilonatommy ilonatommy requested review from tdykstra, a team and BrennanConroy as code owners July 9, 2025 10:32
@ilonatommy ilonatommy requested review from wtgodbe and a team as code owners July 11, 2025 16:54
@ilonatommy ilonatommy added this to the 10.0-preview7 milestone Jul 11, 2025
@ilonatommy ilonatommy requested a review from a team as a code owner July 14, 2025 08:27
@ilonatommy ilonatommy enabled auto-merge (squash) July 14, 2025 10:15
@ilonatommy
Copy link
Member

Templates test with 10.0::10.0.0-preview.7.25364.110, not with the current state of repo. They fail with

src\ProjectTemplates\scripts\MyBlazorApp\Program.cs(18,51): error CS1739: The best overload for 'UseStatusCodePagesWithReExecute' does not have a parameter named 'createScopeForStatusCodePages' 

@copilot revert changes to files in templates, under src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp directory.

…ScopeForStatusCodePages

Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
auto-merge was automatically disabled July 15, 2025 08:38

Head branch was pushed to by a user without write access

Copy link
Contributor Author

Copilot AI commented Jul 15, 2025

Templates test with 10.0::10.0.0-preview.7.25364.110, not with the current state of repo. They fail with

src\ProjectTemplates\scripts\MyBlazorApp\Program.cs(18,51): error CS1739: The best over...

Reverted changes to template files in the BlazorWeb-CSharp directory. The templates now use createScopeForErrors: true instead of createScopeForStatusCodePages: true to be compatible with the older version they are tested against. (07f562f)

Copilot finished work on behalf of ilonatommy July 15, 2025 08:39
Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
@ilonatommy
Copy link
Member

ilonatommy commented Jul 16, 2025

I don't get it. If we don't change templates, they fail with

src\ProjectTemplates\test\Templates.Blazor.Tests\bin\Release\net10.0\TestTemplates\AspNet.vmsroat00q32\Program.cs(18,51): error CS1739: The best overload for 'UseStatusCodePagesWithReExecute' does not have a parameter named 'createScopeForErrors'

If we change them, they fail with

src\ProjectTemplates\scripts\MyBlazorApp\Program.cs(18,51): error CS1739: The best overload for 'UseStatusCodePagesWithReExecute' does not have a parameter named 'createScopeForStatusCodePages' 

Locally I'm hitting #62746. We cannot merge until I figure out how to solve it.

edit: on my machine all the tests are passing. Trying to find a reason for CI to behave differently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Api proposal for UseStatusCodePagesWithReExecute
3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy