Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseExceptionHandler("/Error", createScopeForErrors: true);
}

reexecutionApp.UseStatusCodePagesWithReExecute("/not-found-reexecute", createScopeForErrors: true);
reexecutionApp.UseStatusCodePagesWithReExecute("/not-found-reexecute", createScopeForStatusCodePages: true);
reexecutionApp.UseStaticFiles();
reexecutionApp.UseRouting();
RazorComponentEndpointsStartup<TRootComponent>.UseFakeAuthState(reexecutionApp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
await context.Response.WriteAsync("Triggered a 404 status code.");
});
});
reexecutionApp.UseStatusCodePagesWithReExecute("/not-found-reexecute", createScopeForErrors: true);
reexecutionApp.UseStatusCodePagesWithReExecute("/not-found-reexecute", createScopeForStatusCodePages: true);
reexecutionApp.UseRouting();

reexecutionApp.UseAntiforgery();
Expand Down
8 changes: 5 additions & 3 deletions src/Middleware/Diagnostics/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#nullable enable
Microsoft.AspNetCore.Builder.ExceptionHandlerOptions.SuppressDiagnosticsCallback.get -> System.Func<Microsoft.AspNetCore.Diagnostics.ExceptionHandlerSuppressDiagnosticsContext!, bool>?
Microsoft.AspNetCore.Builder.ExceptionHandlerOptions.SuppressDiagnosticsCallback.set -> void
Microsoft.AspNetCore.Builder.StatusCodePagesOptions.CreateScopeForErrors.get -> bool
Microsoft.AspNetCore.Builder.StatusCodePagesOptions.CreateScopeForErrors.set -> void
Microsoft.AspNetCore.Builder.StatusCodePagesOptions.CreateScopeForStatusCodePages.get -> bool
Microsoft.AspNetCore.Builder.StatusCodePagesOptions.CreateScopeForStatusCodePages.set -> void
Microsoft.AspNetCore.Diagnostics.ExceptionHandledType
Microsoft.AspNetCore.Diagnostics.ExceptionHandledType.ExceptionHandlerDelegate = 3 -> Microsoft.AspNetCore.Diagnostics.ExceptionHandledType
Microsoft.AspNetCore.Diagnostics.ExceptionHandledType.ExceptionHandlerService = 1 -> Microsoft.AspNetCore.Diagnostics.ExceptionHandledType
Expand All @@ -17,4 +17,6 @@ Microsoft.AspNetCore.Diagnostics.ExceptionHandlerSuppressDiagnosticsContext.Exce
Microsoft.AspNetCore.Diagnostics.ExceptionHandlerSuppressDiagnosticsContext.ExceptionHandlerSuppressDiagnosticsContext() -> void
Microsoft.AspNetCore.Diagnostics.ExceptionHandlerSuppressDiagnosticsContext.HttpContext.get -> Microsoft.AspNetCore.Http.HttpContext!
Microsoft.AspNetCore.Diagnostics.ExceptionHandlerSuppressDiagnosticsContext.HttpContext.init -> void
static Microsoft.AspNetCore.Builder.StatusCodePagesExtensions.UseStatusCodePagesWithReExecute(this Microsoft.AspNetCore.Builder.IApplicationBuilder! app, string! pathFormat, bool createScopeForErrors, string? queryFormat = null) -> Microsoft.AspNetCore.Builder.IApplicationBuilder!
static Microsoft.AspNetCore.Builder.StatusCodePagesExtensions.UseStatusCodePagesWithReExecute(this Microsoft.AspNetCore.Builder.IApplicationBuilder! app, string! pathFormat, string? queryFormat = null, bool createScopeForStatusCodePages = false) -> Microsoft.AspNetCore.Builder.IApplicationBuilder!
*REMOVED*static Microsoft.AspNetCore.Builder.StatusCodePagesExtensions.UseStatusCodePagesWithReExecute(this Microsoft.AspNetCore.Builder.IApplicationBuilder! app, string! pathFormat, string? queryFormat = null) -> Microsoft.AspNetCore.Builder.IApplicationBuilder!
static Microsoft.AspNetCore.Builder.StatusCodePagesExtensions.UseStatusCodePagesWithReExecute(this Microsoft.AspNetCore.Builder.IApplicationBuilder! app, string! pathFormat, string! queryFormat) -> Microsoft.AspNetCore.Builder.IApplicationBuilder!
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public static IApplicationBuilder UseStatusCodePages(this IApplicationBuilder ap
return app.UseStatusCodePages(context => tangent(context.HttpContext));
}

// 1.0 BACKCOMPAT OVERLOAD -- DO NOT TOUCH
/// <summary>
/// Adds a StatusCodePages middleware to the pipeline. Specifies that the response body should be generated by
/// re-executing the request pipeline using an alternate path. This path may contain a '{0}' placeholder of the status code.
Expand All @@ -144,7 +145,7 @@ public static IApplicationBuilder UseStatusCodePages(this IApplicationBuilder ap
public static IApplicationBuilder UseStatusCodePagesWithReExecute(
this IApplicationBuilder app,
string pathFormat,
string? queryFormat = null)
string queryFormat)
{
ArgumentNullException.ThrowIfNull(app);

Expand All @@ -168,15 +169,15 @@ public static IApplicationBuilder UseStatusCodePagesWithReExecute(
/// </summary>
/// <param name="app"></param>
/// <param name="pathFormat"></param>
/// <param name="createScopeForErrors">Whether or not to create a new <see cref="IServiceProvider"/> scope.</param>
/// <param name="queryFormat"></param>
/// <param name="createScopeForStatusCodePages">Whether or not to create a new <see cref="IServiceProvider"/> scope.</param>
/// <returns></returns>
[SuppressMessage("ApiDesign", "RS0026:Do not add multiple overloads with optional parameters", Justification = "Required to maintain compatibility")]
public static IApplicationBuilder UseStatusCodePagesWithReExecute(
this IApplicationBuilder app,
string pathFormat,
bool createScopeForErrors,
string? queryFormat = null)
string? queryFormat = null,
bool createScopeForStatusCodePages = false)
{
ArgumentNullException.ThrowIfNull(app);

Expand All @@ -190,7 +191,7 @@ public static IApplicationBuilder UseStatusCodePagesWithReExecute(
Options.Create(new StatusCodePagesOptions()
{
HandleAsync = CreateHandler(pathFormat, queryFormat, newNext),
CreateScopeForErrors = createScopeForErrors,
CreateScopeForStatusCodePages = createScopeForStatusCodePages,
PathFormat = pathFormat
})).Invoke;
});
Expand All @@ -199,7 +200,7 @@ public static IApplicationBuilder UseStatusCodePagesWithReExecute(
var options = new StatusCodePagesOptions
{
HandleAsync = CreateHandler(pathFormat, queryFormat),
CreateScopeForErrors = createScopeForErrors,
CreateScopeForStatusCodePages = createScopeForStatusCodePages,
PathFormat = pathFormat
};
var wrappedOptions = new OptionsWrapper<StatusCodePagesOptions>(options);
Expand All @@ -222,8 +223,8 @@ private static Func<StatusCodeContext, Task> CreateHandler(string pathFormat, st
var originalQueryString = context.HttpContext.Request.QueryString;

var routeValuesFeature = context.HttpContext.Features.Get<IRouteValuesFeature>();
var oldScope = context.Options.CreateScopeForErrors ? context.HttpContext.RequestServices : null;
await using AsyncServiceScope? scope = context.Options.CreateScopeForErrors
var oldScope = context.Options.CreateScopeForStatusCodePages ? context.HttpContext.RequestServices : null;
await using AsyncServiceScope? scope = context.Options.CreateScopeForStatusCodePages
? context.HttpContext.RequestServices.GetRequiredService<IServiceScopeFactory>().CreateAsyncScope()
: null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private static string BuildResponseBody(int httpStatusCode)
/// replace it on <see cref="HttpContext.RequestServices"/> when re-executing the request.
/// </summary>
/// <remarks>The default value is <see langword="false"/>.</remarks>
public bool CreateScopeForErrors { get; set; }
public bool CreateScopeForStatusCodePages { get; set; }

internal string? PathFormat { get; set; }
}
Loading