Skip to content

Commit 1730530

Browse files
Copilotilonatommyjaviercn
authored
Add CreateScopeForStatusCodePages property and UseStatusCodePagesWithReExecute overload (#62624)
* Initial plan * Implement CreateScopeForStatusCodePages API with renamed property and new overload Co-authored-by: ilonatommy <[email protected]> * Address PR feedback: remove test, fix nullability, add comments Co-authored-by: ilonatommy <[email protected]> * Revert test file changes as requested Co-authored-by: ilonatommy <[email protected]> * Fix updating "Shipped.txt". * Revert googletest changes. * Fix template tests. * Fix. * Revert template changes to use createScopeForErrors instead of createScopeForStatusCodePages Co-authored-by: ilonatommy <[email protected]> * Remove backcompat comment from StatusCodePagesExtensions Co-authored-by: javiercn <[email protected]> * Revert 07f562f. * Remove UseStatusCodePagesWithReExecute calls from template files Co-authored-by: ilonatommy <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: ilonatommy <[email protected]> Co-authored-by: Ilona Tomkowicz <[email protected]> Co-authored-by: javiercn <[email protected]>
1 parent 2e9bff6 commit 1730530

File tree

7 files changed

+16
-17
lines changed

7 files changed

+16
-17
lines changed

src/Components/test/testassets/Components.TestServer/RazorComponentEndpointsNoInteractivityStartup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
6464
app.UseExceptionHandler("/Error", createScopeForErrors: true);
6565
}
6666

67-
reexecutionApp.UseStatusCodePagesWithReExecute("/not-found-reexecute", createScopeForErrors: true);
67+
reexecutionApp.UseStatusCodePagesWithReExecute("/not-found-reexecute", createScopeForStatusCodePages: true);
6868
reexecutionApp.UseStaticFiles();
6969
reexecutionApp.UseRouting();
7070
RazorComponentEndpointsStartup<TRootComponent>.UseFakeAuthState(reexecutionApp);

src/Components/test/testassets/Components.TestServer/RazorComponentEndpointsStartup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
103103
await context.Response.WriteAsync("Triggered a 404 status code.");
104104
});
105105
});
106-
reexecutionApp.UseStatusCodePagesWithReExecute("/not-found-reexecute", createScopeForErrors: true);
106+
reexecutionApp.UseStatusCodePagesWithReExecute("/not-found-reexecute", createScopeForStatusCodePages: true);
107107
reexecutionApp.UseRouting();
108108

109109
reexecutionApp.UseAntiforgery();

src/Middleware/Diagnostics/src/PublicAPI.Unshipped.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#nullable enable
22
Microsoft.AspNetCore.Builder.ExceptionHandlerOptions.SuppressDiagnosticsCallback.get -> System.Func<Microsoft.AspNetCore.Diagnostics.ExceptionHandlerSuppressDiagnosticsContext!, bool>?
33
Microsoft.AspNetCore.Builder.ExceptionHandlerOptions.SuppressDiagnosticsCallback.set -> void
4-
Microsoft.AspNetCore.Builder.StatusCodePagesOptions.CreateScopeForErrors.get -> bool
5-
Microsoft.AspNetCore.Builder.StatusCodePagesOptions.CreateScopeForErrors.set -> void
4+
Microsoft.AspNetCore.Builder.StatusCodePagesOptions.CreateScopeForStatusCodePages.get -> bool
5+
Microsoft.AspNetCore.Builder.StatusCodePagesOptions.CreateScopeForStatusCodePages.set -> void
66
Microsoft.AspNetCore.Diagnostics.ExceptionHandledType
77
Microsoft.AspNetCore.Diagnostics.ExceptionHandledType.ExceptionHandlerDelegate = 3 -> Microsoft.AspNetCore.Diagnostics.ExceptionHandledType
88
Microsoft.AspNetCore.Diagnostics.ExceptionHandledType.ExceptionHandlerService = 1 -> Microsoft.AspNetCore.Diagnostics.ExceptionHandledType
@@ -17,4 +17,6 @@ Microsoft.AspNetCore.Diagnostics.ExceptionHandlerSuppressDiagnosticsContext.Exce
1717
Microsoft.AspNetCore.Diagnostics.ExceptionHandlerSuppressDiagnosticsContext.ExceptionHandlerSuppressDiagnosticsContext() -> void
1818
Microsoft.AspNetCore.Diagnostics.ExceptionHandlerSuppressDiagnosticsContext.HttpContext.get -> Microsoft.AspNetCore.Http.HttpContext!
1919
Microsoft.AspNetCore.Diagnostics.ExceptionHandlerSuppressDiagnosticsContext.HttpContext.init -> void
20-
static Microsoft.AspNetCore.Builder.StatusCodePagesExtensions.UseStatusCodePagesWithReExecute(this Microsoft.AspNetCore.Builder.IApplicationBuilder! app, string! pathFormat, bool createScopeForErrors, string? queryFormat = null) -> Microsoft.AspNetCore.Builder.IApplicationBuilder!
20+
static Microsoft.AspNetCore.Builder.StatusCodePagesExtensions.UseStatusCodePagesWithReExecute(this Microsoft.AspNetCore.Builder.IApplicationBuilder! app, string! pathFormat, string? queryFormat = null, bool createScopeForStatusCodePages = false) -> Microsoft.AspNetCore.Builder.IApplicationBuilder!
21+
*REMOVED*static Microsoft.AspNetCore.Builder.StatusCodePagesExtensions.UseStatusCodePagesWithReExecute(this Microsoft.AspNetCore.Builder.IApplicationBuilder! app, string! pathFormat, string? queryFormat = null) -> Microsoft.AspNetCore.Builder.IApplicationBuilder!
22+
static Microsoft.AspNetCore.Builder.StatusCodePagesExtensions.UseStatusCodePagesWithReExecute(this Microsoft.AspNetCore.Builder.IApplicationBuilder! app, string! pathFormat, string! queryFormat) -> Microsoft.AspNetCore.Builder.IApplicationBuilder!

src/Middleware/Diagnostics/src/StatusCodePage/StatusCodePagesExtensions.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public static IApplicationBuilder UseStatusCodePages(this IApplicationBuilder ap
144144
public static IApplicationBuilder UseStatusCodePagesWithReExecute(
145145
this IApplicationBuilder app,
146146
string pathFormat,
147-
string? queryFormat = null)
147+
string queryFormat)
148148
{
149149
ArgumentNullException.ThrowIfNull(app);
150150

@@ -168,15 +168,15 @@ public static IApplicationBuilder UseStatusCodePagesWithReExecute(
168168
/// </summary>
169169
/// <param name="app"></param>
170170
/// <param name="pathFormat"></param>
171-
/// <param name="createScopeForErrors">Whether or not to create a new <see cref="IServiceProvider"/> scope.</param>
172171
/// <param name="queryFormat"></param>
172+
/// <param name="createScopeForStatusCodePages">Whether or not to create a new <see cref="IServiceProvider"/> scope.</param>
173173
/// <returns></returns>
174174
[SuppressMessage("ApiDesign", "RS0026:Do not add multiple overloads with optional parameters", Justification = "Required to maintain compatibility")]
175175
public static IApplicationBuilder UseStatusCodePagesWithReExecute(
176176
this IApplicationBuilder app,
177177
string pathFormat,
178-
bool createScopeForErrors,
179-
string? queryFormat = null)
178+
string? queryFormat = null,
179+
bool createScopeForStatusCodePages = false)
180180
{
181181
ArgumentNullException.ThrowIfNull(app);
182182

@@ -190,7 +190,7 @@ public static IApplicationBuilder UseStatusCodePagesWithReExecute(
190190
Options.Create(new StatusCodePagesOptions()
191191
{
192192
HandleAsync = CreateHandler(pathFormat, queryFormat, newNext),
193-
CreateScopeForErrors = createScopeForErrors,
193+
CreateScopeForStatusCodePages = createScopeForStatusCodePages,
194194
PathFormat = pathFormat
195195
})).Invoke;
196196
});
@@ -199,7 +199,7 @@ public static IApplicationBuilder UseStatusCodePagesWithReExecute(
199199
var options = new StatusCodePagesOptions
200200
{
201201
HandleAsync = CreateHandler(pathFormat, queryFormat),
202-
CreateScopeForErrors = createScopeForErrors,
202+
CreateScopeForStatusCodePages = createScopeForStatusCodePages,
203203
PathFormat = pathFormat
204204
};
205205
var wrappedOptions = new OptionsWrapper<StatusCodePagesOptions>(options);
@@ -222,8 +222,8 @@ private static Func<StatusCodeContext, Task> CreateHandler(string pathFormat, st
222222
var originalQueryString = context.HttpContext.Request.QueryString;
223223

224224
var routeValuesFeature = context.HttpContext.Features.Get<IRouteValuesFeature>();
225-
var oldScope = context.Options.CreateScopeForErrors ? context.HttpContext.RequestServices : null;
226-
await using AsyncServiceScope? scope = context.Options.CreateScopeForErrors
225+
var oldScope = context.Options.CreateScopeForStatusCodePages ? context.HttpContext.RequestServices : null;
226+
await using AsyncServiceScope? scope = context.Options.CreateScopeForStatusCodePages
227227
? context.HttpContext.RequestServices.GetRequiredService<IServiceScopeFactory>().CreateAsyncScope()
228228
: null;
229229

src/Middleware/Diagnostics/src/StatusCodePage/StatusCodePagesOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private static string BuildResponseBody(int httpStatusCode)
6161
/// replace it on <see cref="HttpContext.RequestServices"/> when re-executing the request.
6262
/// </summary>
6363
/// <remarks>The default value is <see langword="false"/>.</remarks>
64-
public bool CreateScopeForErrors { get; set; }
64+
public bool CreateScopeForStatusCodePages { get; set; }
6565

6666
internal string? PathFormat { get; set; }
6767
}

src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Program.Main.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ public static void Main(string[] args)
107107
#endif
108108
}
109109

110-
app.UseStatusCodePagesWithReExecute("/not-found", createScopeForErrors: true);
111-
112110
#if (HasHttpsProfile)
113111
app.UseHttpsRedirection();
114112

src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Program.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@
100100
app.UseHsts();
101101
#endif
102102
}
103-
app.UseStatusCodePagesWithReExecute("/not-found", createScopeForErrors: true);
104103

105104
#if (HasHttpsProfile)
106105
app.UseHttpsRedirection();

0 commit comments

Comments
 (0)