Default model binding for form requests consumes body automatically, causing Request Forwarding Issues #61043
Labels
area-networking
Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Is there an existing issue for this?
Describe the bug
Issue Summary
When an API endpoint in ASP.NET Core has a FromHeader parameter and the request’s Content-Type is application/x-www-form-urlencoded, ASP.NET Core automatically reads the request body, even if no parameters are bound from the form. This behavior interferes with request forwarding using YARP as the request body can only be read once.
Related code:
aspnetcore/src/Mvc/Mvc.Core/src/ModelBinding/FormValueProviderFactory.cs
Line 39 in 667b514
aspnetcore/src/Mvc/Mvc.Core/src/ModelBinding/FormFileValueProviderFactory.cs
Line 37 in 667b514
aspnetcore/src/Mvc/Mvc.Core/src/ModelBinding/JQueryFormValueProviderFactory.cs
Line 39 in 667b514
Expected Behavior
Steps To Reproduce
https://github.com/divyeshio/ModelBindingRepro
Exceptions (if any)
.NET Version
9.0.200
Anything else?
.NET SDK:
Version: 9.0.200
Commit: 90e8b202f2
Workload version: 9.0.200-manifests.b4a8049f
MSBuild version: 17.13.8+cbc39bea8
Runtime Environment:
OS Name: Mac OS X
OS Version: 15.3
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/9.0.200/
.NET workloads installed:
There are no installed workloads to display.
Configured to use loose manifests when installing new manifests.
Host:
Version: 9.0.2
Architecture: arm64
Commit: 80aa709f5d
.NET SDKs installed:
9.0.200 [/usr/local/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 9.0.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 9.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
Not set
global.json file:
Not found
The text was updated successfully, but these errors were encountered: