diff --git a/src/Components/Endpoints/src/RazorComponentEndpointInvoker.cs b/src/Components/Endpoints/src/RazorComponentEndpointInvoker.cs index 02bf4e3a34679..276c1ba8c51aa 100644 --- a/src/Components/Endpoints/src/RazorComponentEndpointInvoker.cs +++ b/src/Components/Endpoints/src/RazorComponentEndpointInvoker.cs @@ -163,11 +163,22 @@ private async Task ValidateRequestAsync(HttpContext cont // want to run the form handling logic against the error page. context.Features.Get() == null; + if (processPost) { - var valid = false; + if (!context.Request.HasFormContentType) + { + context.Response.StatusCode = StatusCodes.Status400BadRequest; + if (context.RequestServices.GetService()?.IsDevelopment() == true) + { + await context.Response.WriteAsync("The request has an incorrect Content-type."); + } + return RequestValidationState.InvalidPostRequest; + } + // Respect the token validation done by the middleware _if_ it has been set, otherwise // run the validation here. + var valid = false; if (context.Features.Get() is { } antiForgeryValidationFeature) { if (!antiForgeryValidationFeature.IsValid)