-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Add NotFoundPage
to Router
#60970
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
Add NotFoundPage
to Router
#60970
Changes from 37 commits
11956ec
216ec31
3168993
067cfd2
6d22aad
6ea7082
25e8e66
1060b4d
fc696c3
44e7d8e
ae68011
39deb2b
6b620d5
6876252
74e3eae
e10b90c
b660d19
d566c4b
d41bd5b
005f217
8c7b6d2
f876e4d
8744e8b
aee53a9
de91b4b
7e7f1fe
6a10062
5518812
c8eb629
66b563c
1da92f9
b7775ef
cb32f94
8273758
c31812c
b162946
f57b0b7
3e77c62
d612592
cd5dffa
b416805
fc63304
c0e7f86
124b470
ebdf9a9
fc49fe6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -39,12 +39,17 @@ private async Task RenderComponentCore(HttpContext context) | |||
{ | ||||
context.Response.ContentType = RazorComponentResultExecutor.DefaultContentType; | ||||
var isErrorHandler = context.Features.Get<IExceptionHandlerFeature>() is not null; | ||||
var hasStatusCodePage = context.Features.Get<IStatusCodePagesFeature>() is not null; | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the interface we are looking for is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This complicates the logic a bit. We need a way to avoid writing the response (so return from We could set Otherwise, we will return too early to handle re-execution, again this condition: aspnetcore/src/Middleware/Diagnostics/src/StatusCodePage/StatusCodePagesMiddleware.cs Line 67 in 55a1ae7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Relying on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In error handler we don't have such a problem (we don't have to detect to return early) because the thrown exception does it for us. We never execute any code after There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't fully follow, but I don't think we need to block on this |
||||
if (isErrorHandler) | ||||
{ | ||||
Log.InteractivityDisabledForErrorHandling(_logger); | ||||
} | ||||
_renderer.InitializeStreamingRenderingFraming(context, isErrorHandler); | ||||
EndpointHtmlRenderer.MarkAsAllowingEnhancedNavigation(context); | ||||
_renderer.InitializeStreamingRenderingFraming(context, isErrorHandler, hasStatusCodePage); | ||||
bool avoidEditingHeaders = hasStatusCodePage && context.Response.StatusCode == StatusCodes.Status404NotFound; | ||||
if (!avoidEditingHeaders) | ||||
{ | ||||
EndpointHtmlRenderer.MarkAsAllowingEnhancedNavigation(context); | ||||
} | ||||
|
||||
var endpoint = context.GetEndpoint() ?? throw new InvalidOperationException($"An endpoint must be set on the '{nameof(HttpContext)}'."); | ||||
|
||||
|
@@ -85,14 +90,26 @@ await _renderer.InitializeStandardComponentServicesAsync( | |||
await using var writer = new HttpResponseStreamWriter(context.Response.Body, Encoding.UTF8, defaultBufferSize, ArrayPool<byte>.Shared, ArrayPool<char>.Shared); | ||||
using var bufferWriter = new BufferedTextWriter(writer); | ||||
|
||||
int originalStatusCode = context.Response.StatusCode; | ||||
bool isErrorHandlerOrHasStatusCodePage = isErrorHandler || hasStatusCodePage; | ||||
|
||||
// Note that we always use Static rendering mode for the top-level output from a RazorComponentResult, | ||||
// because you never want to serialize the invocation of RazorComponentResultHost. Instead, that host | ||||
// component takes care of switching into your desired render mode when it produces its own output. | ||||
var htmlContent = await _renderer.RenderEndpointComponent( | ||||
context, | ||||
rootComponent, | ||||
ParameterView.Empty, | ||||
waitForQuiescence: result.IsPost || isErrorHandler); | ||||
waitForQuiescence: result.IsPost || isErrorHandlerOrHasStatusCodePage); | ||||
|
||||
bool requiresReexecution = originalStatusCode != context.Response.StatusCode && hasStatusCodePage; | ||||
if (requiresReexecution) | ||||
{ | ||||
// If the response is a 404, we don't want to write any content. | ||||
// This is because the 404 status code is used by the routing middleware | ||||
// to indicate that no endpoint was found for the request. | ||||
return; | ||||
} | ||||
|
||||
Task quiesceTask; | ||||
if (!result.IsPost) | ||||
|
@@ -145,7 +162,7 @@ await _renderer.InitializeStandardComponentServicesAsync( | |||
} | ||||
|
||||
// Emit comment containing state. | ||||
if (!isErrorHandler) | ||||
if (!isErrorHandlerOrHasStatusCodePage) | ||||
{ | ||||
var componentStateHtmlContent = await _renderer.PrerenderPersistedStateAsync(context); | ||||
componentStateHtmlContent.WriteTo(bufferWriter, HtmlEncoder.Default); | ||||
|
@@ -160,10 +177,11 @@ await _renderer.InitializeStandardComponentServicesAsync( | |||
private async Task<RequestValidationState> ValidateRequestAsync(HttpContext context, IAntiforgery? antiforgery) | ||||
{ | ||||
var processPost = HttpMethods.IsPost(context.Request.Method) && | ||||
// Disable POST functionality during exception handling. | ||||
// Disable POST functionality during exception handling and reexecution. | ||||
// The exception handler middleware will not update the request method, and we don't | ||||
// want to run the form handling logic against the error page. | ||||
context.Features.Get<IExceptionHandlerFeature>() == null; | ||||
context.Features.Get<IExceptionHandlerFeature>() == null && | ||||
context.Features.Get<IStatusCodePagesFeature>() == null; | ||||
|
||||
if (processPost) | ||||
{ | ||||
|
Uh oh!
There was an error while loading. Please reload this page.