-
Notifications
You must be signed in to change notification settings - Fork 10.3k
In Production, a non-GET request returns 400 Bad Request instead of 500 when a server error happens #23759
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
Comments
What do the server logs say? |
Similar to all other unhandled exception in requests:
|
This is related to #18186. The HTTP verb from the initial request is used when executing the error handler [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
+ [IgnoreAntiforgeryToken]
public class ErrorModel : PageModel I suppose we should do this in the templates by default if we aren't planning on addressing the linked issue for 5.0. |
Thanks, can confirm this works and is correct. Also explains why the API template does not have this problem. However it's strange that the problem does not happen in Development even with |
That's likely because |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
A fix for this would be add |
Describe the bug
In a ASP.NET Core Website project with Razor Pages (and then add API Controller), if a non-GET request failed due to unhandled exception, 400 Bad Request respond is returned instead of 500.
To Reproduce
Repo
It's very simple to reproduce:
Create a new project with Web Application template (does not happen to API Template).
Add a new API Controller with simple actions that just throw any exception like in the repo file.
Add
endpoints.MapControllers();
so Controllers work. Optionally removeapp.UseDeveloperExceptionPage();
to prove that in Development, the problem does not happen even with this page disabled.Set the Debug Environment Variable
ASPNETCORE_ENVIRONMENT
toProduction
Try to access the endpoint with different verbs, only GET returns 500 while POST, PUT and DELETE returns 400.
Exceptions (if any)
None
Further technical details
ASP.NET Core version: 3.1.0
Include the output of
dotnet --info
The text was updated successfully, but these errors were encountered: