-
Couldn't load subscription status.
- Fork 10.5k
Closed
Description
Describe the bug
A controller action that returns non-success HTTP status code that is re-executed by UseStatusCodePagesWithReExecute is invoked twice.
To Reproduce
Steps to reproduce the behavior:
- Using this version of ASP.NET Core 3.0
- Run this code
public async Task<IActionResult> IndexAsync(string returnUrl)
{
if (!string.IsNullOrEmpty(returnUrl) && returnUrl[0] != '/')
{
return this.BadRequest();
}
return this.View();
} app.UseStatusCodePagesWithReExecute("/error", "?{0}");
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(name: "error", pattern: "error", defaults: new { controller = "Error", action = "Error" });
endpoints.MapControllerRoute(name: "default", pattern: "{controller=Home}/{action=Index}/{id?}");
});- With these arguments
returnUrl = "a" - See error
See that IndexAsync is called initially withreturnUrl == "a", and thenUseStatusCodePagesWithReExecutetriggered a second request. However, instead of hitting the ErrorController, the same controller is hit and IndexAsync is called withreturnUrl == null
Expected behavior
Expected to have app.UseStatusCodePagesWithReExecute("/error", "?{0}"); routed to ErrorController
Screenshots
None
Additional context
Original report #11233
Fixed by c54a720
Broken again by #13068. In this commit, it reverted the change to clear endpoint after the endpoint middleware finished running. However, it only takes care of thrown exception, but does not take care of controller returning status code result.
Metadata
Metadata
Assignees
Labels
No labels