Skip to content

Re-execution middleware works with POST #62267

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

Merged
merged 2 commits into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -175,11 +175,10 @@ 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 and reexecution.
// Disable POST functionality during exception handling.
// 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<IStatusCodePagesFeature>() == null;
context.Features.Get<IExceptionHandlerFeature>() == null;

if (processPost)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ public void CanDispatchToTheDefaultForm(bool suppressEnhancedNavigation)
DispatchToFormCore(dispatchToForm);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void CanDispatchToTheDefaultFormWithReExecutionMiddleware(bool suppressEnhancedNavigation)
{
var dispatchToForm = new DispatchToForm(this)
{
Url = "reexecution/forms/default-form",
FormCssSelector = "form",
SuppressEnhancedNavigation = suppressEnhancedNavigation,
};
DispatchToFormCore(dispatchToForm);
}

[Fact]
public void PlainFormIsNotEnhancedByDefault()
{
Expand Down Expand Up @@ -891,6 +905,21 @@ public async Task CanModifyTheHttpResponseDuringEventHandling()
Assert.Equal("ModifyHttpContext", cookie.Value);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void FormNoAntiforgeryReturnBadRequestWithReExecutionMiddleware(bool suppressEnhancedNavigation)
{
var dispatchToForm = new DispatchToForm(this)
{
Url = "reexecution/forms/no-antiforgery",
FormCssSelector = "form",
ShouldCauseBadRequest = true,
SuppressEnhancedNavigation = suppressEnhancedNavigation,
};
DispatchToFormCore(dispatchToForm);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
Expand Down Expand Up @@ -973,6 +1002,21 @@ public void FormNoHandlerReturnBadRequest(bool suppressEnhancedNavigation)
DispatchToFormCore(dispatchToForm);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void FormNoHandlerReturnBadRequestWithReExecutionMiddleware(bool suppressEnhancedNavigation)
{
var dispatchToForm = new DispatchToForm(this)
{
Url = "reexecution/forms/no-handler",
FormCssSelector = "form",
ShouldCauseBadRequest = true,
SuppressEnhancedNavigation = suppressEnhancedNavigation,
};
DispatchToFormCore(dispatchToForm);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@page "/forms/default-form"
@page "/reexecution/forms/default-form"
@using Microsoft.AspNetCore.Components.Forms

<h2>Default form</h2>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@page "/forms/no-antiforgery"
@page "/reexecution/forms/no-antiforgery"
@using Microsoft.AspNetCore.Components.Forms

<h2>Default form</h2>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@page "/forms/no-handler"
@page "/reexecution/forms/no-handler"
@using Microsoft.AspNetCore.Components.Forms

<h2>Form with no handler</h2>
Expand Down
Loading