Middleware skipped when UseEndpoints is called multiple times
See original GitHub issueDescribe the bug
Middleware between two calls to configure endpoint routing using app.UseEndpoints(...)
is never executed.
Expected:
Looking at this startup code, I would expect SetUser()
middleware to be executed before MVC controller.
Actual: The breakpoint is never hit.
To Reproduce
Create a new ASP.NET Core 3.1 MVC web application. Replace Startup.cs
with this: https://gist.github.com/jussimattila/047ab4936f943ed8b0f2a6574c2525a5
Set a breakpoint to the middleware, confirm it is not executed.
Further technical details
- ASP.NET Core 3.1
C:\Users\Jussi>dotnet --info
.NET Core SDK (reflecting any global.json):
Version: 3.1.100
Commit: cd82f021f4
Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.1.100\
Host (useful for support):
Version: 3.1.0
Commit: 65f04fb6db
- Visual Studio 2019 16.4
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Why is middleware not executed when there are multiple ...
So yes, you can use UseEndpoints(…) multiple times but it will likely not do what you expect it to do. All configuration delegates...
Read more >Why is middleware not executed when there are multiple calls ...
So yes, you can use UseEndpoints(…) multiple times but it will likely not do what you expect it to do. All configuration delegates...
Read more >Routing in ASP.NET Core
The UseEndpoints middleware is terminal when a match is found. Terminal middleware is defined later in this article.
Read more >MVC1005: Cannot use UseMvc with Endpoint Routing
Using MVC via UseMvc or UseMvcWithDefaultRoute requires an explicit opt-in inside Startup.ConfigureServices . This is required because MVC ...
Read more >ASP.NET Core Middleware Components
ASP.NET Core Middleware Components are components that are used to handle the HTTP Request and Response in .NET Core application.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@mkArtakMSFT we have exactly the same problem, please “allow” to call app.UseEndPoints multiple times and execute all configured middlewares. br
@mkArtakMSFT This issue isn’t a question or a discussion. This is a bug 🐛 🙈