Skip to content

Commit 1415d9b

Browse files
authored
Re-execution middleware works with POST (#62267)
* Add tests for forms under a route with re-execution middleware. * Fix - treat POST as POST, even when re-execution middleware is set.
1 parent 07b2f0a commit 1415d9b

File tree

5 files changed

+49
-3
lines changed

5 files changed

+49
-3
lines changed

src/Components/Endpoints/src/RazorComponentEndpointInvoker.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,10 @@ await _renderer.InitializeStandardComponentServicesAsync(
175175
private async Task<RequestValidationState> ValidateRequestAsync(HttpContext context, IAntiforgery? antiforgery)
176176
{
177177
var processPost = HttpMethods.IsPost(context.Request.Method) &&
178-
// Disable POST functionality during exception handling and reexecution.
178+
// Disable POST functionality during exception handling.
179179
// The exception handler middleware will not update the request method, and we don't
180180
// want to run the form handling logic against the error page.
181-
context.Features.Get<IExceptionHandlerFeature>() == null &&
182-
context.Features.Get<IStatusCodePagesFeature>() == null;
181+
context.Features.Get<IExceptionHandlerFeature>() == null;
183182

184183
if (processPost)
185184
{

src/Components/test/E2ETest/ServerRenderingTests/FormHandlingTests/FormWithParentBindingContextTest.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ public void CanDispatchToTheDefaultForm(bool suppressEnhancedNavigation)
4949
DispatchToFormCore(dispatchToForm);
5050
}
5151

52+
[Theory]
53+
[InlineData(true)]
54+
[InlineData(false)]
55+
public void CanDispatchToTheDefaultFormWithReExecutionMiddleware(bool suppressEnhancedNavigation)
56+
{
57+
var dispatchToForm = new DispatchToForm(this)
58+
{
59+
Url = "reexecution/forms/default-form",
60+
FormCssSelector = "form",
61+
SuppressEnhancedNavigation = suppressEnhancedNavigation,
62+
};
63+
DispatchToFormCore(dispatchToForm);
64+
}
65+
5266
[Fact]
5367
public void PlainFormIsNotEnhancedByDefault()
5468
{
@@ -891,6 +905,21 @@ public async Task CanModifyTheHttpResponseDuringEventHandling()
891905
Assert.Equal("ModifyHttpContext", cookie.Value);
892906
}
893907

908+
[Theory]
909+
[InlineData(true)]
910+
[InlineData(false)]
911+
public void FormNoAntiforgeryReturnBadRequestWithReExecutionMiddleware(bool suppressEnhancedNavigation)
912+
{
913+
var dispatchToForm = new DispatchToForm(this)
914+
{
915+
Url = "reexecution/forms/no-antiforgery",
916+
FormCssSelector = "form",
917+
ShouldCauseBadRequest = true,
918+
SuppressEnhancedNavigation = suppressEnhancedNavigation,
919+
};
920+
DispatchToFormCore(dispatchToForm);
921+
}
922+
894923
[Theory]
895924
[InlineData(true)]
896925
[InlineData(false)]
@@ -973,6 +1002,21 @@ public void FormNoHandlerReturnBadRequest(bool suppressEnhancedNavigation)
9731002
DispatchToFormCore(dispatchToForm);
9741003
}
9751004

1005+
[Theory]
1006+
[InlineData(true)]
1007+
[InlineData(false)]
1008+
public void FormNoHandlerReturnBadRequestWithReExecutionMiddleware(bool suppressEnhancedNavigation)
1009+
{
1010+
var dispatchToForm = new DispatchToForm(this)
1011+
{
1012+
Url = "reexecution/forms/no-handler",
1013+
FormCssSelector = "form",
1014+
ShouldCauseBadRequest = true,
1015+
SuppressEnhancedNavigation = suppressEnhancedNavigation,
1016+
};
1017+
DispatchToFormCore(dispatchToForm);
1018+
}
1019+
9761020
[Theory]
9771021
[InlineData(true)]
9781022
[InlineData(false)]

src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/Forms/DefaultForm.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@page "/forms/default-form"
2+
@page "/reexecution/forms/default-form"
23
@using Microsoft.AspNetCore.Components.Forms
34

45
<h2>Default form</h2>

src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/Forms/FormNoAntiforgery.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@page "/forms/no-antiforgery"
2+
@page "/reexecution/forms/no-antiforgery"
23
@using Microsoft.AspNetCore.Components.Forms
34

45
<h2>Default form</h2>

src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/Forms/FormNoHandler.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@page "/forms/no-handler"
2+
@page "/reexecution/forms/no-handler"
23
@using Microsoft.AspNetCore.Components.Forms
34

45
<h2>Form with no handler</h2>

0 commit comments

Comments
 (0)