question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Correct Endpoint ignored by EndpointRoutingMiddleware

See original GitHub issue

Describe the bug

In UseEndpoints, I have a custom MapBlog and mvc route mappings

The MapBlog maps blog/{**slug} to a new IApplicationBuilder which uses a proxy middleware.

Some of the route mappings contain multiple constraints, and this somehow removes blog/{**slug} from consideration.

Example of this: {a:regex(^defaultValue$}/{b:regex(^defaultValue$}

In reality the endpoints in my project are more complex than this, but this is enough to reproduce

To Reproduce

https://github.com/serenata-keith-mifsud/AspNetCore3.1RoutingIssue

static async Task EmptyResponse(HttpContext context)
            {
                await context.Response.WriteAsync($"Hello World from {context.GetEndpoint().DisplayName}!");
            }

app.UseEndpoints(endpoints =>
            {
                endpoints.Map("blog/{**blog}", endpoints.CreateApplicationBuilder().Use(next => EmptyResponse).Build()).WithDisplayName("Blog");
                endpoints.MapControllerRoute("HomePage", "/", new { controller = "Home", action = "Index" }).WithDisplayName("HomePage");
                endpoints.MapControllerRoute("TwoConstraints", "{a:regex(^a$)}/{b:regex(^b$)}", new { controller = "Home", action = "Index" }).WithDisplayName("TwoConstaints");
            });

Microsoft.AspNetCore.Routing.Matching.DfaMatcher: Debug: 1 candidate(s) found for the request path ‘/blog/post’ Microsoft.AspNetCore.Routing.Matching.DfaMatcher: Debug: Endpoint ‘TwoConstaints’ with route pattern ‘{a:regex(^a$)}/{b:regex(^b$)}’ was rejected by constraint ‘a’:‘Microsoft.AspNetCore.Routing.Constraints.RegexInlineRouteConstraint’ with value ‘blog’ for the request path ‘/blog/post’ Microsoft.AspNetCore.Routing.Matching.DfaMatcher: Debug: Endpoint ‘TwoConstaints’ with route pattern ‘{a:regex(^a$)}/{b:regex(^b$)}’ is not valid for the request path ‘/blog/post’ Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware: Debug: Request did not match any endpoints

Further technical details

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

.NET Core SDKs installed: 2.0.2 [C:\Program Files\dotnet\sdk] 2.1.202 [C:\Program Files\dotnet\sdk] 2.1.509 [C:\Program Files\dotnet\sdk] 2.1.802 [C:\Program Files\dotnet\sdk] 2.2.402 [C:\Program Files\dotnet\sdk] 3.0.100 [C:\Program Files\dotnet\sdk] 3.1.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.2.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

IDE: Microsoft Visual Studio Professional 2019 Version 16.4.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
serenata-keith-mifsudcommented, Jun 10, 2020

Yes thank you, had to use the switch as described here https://github.com/dotnet/aspnetcore/issues/21114

0reactions
mkArtakMSFTcommented, Jun 9, 2020

This should already be fixed in the latest 3.1 patch.

Read more comments on GitHub >

github_iconTop Results From Across the Web

EndpointRoutingMiddleware matches endpoints setup by ...
InvalidOperationException: EndpointRoutingMiddleware matches endpoints setup by EndpointMiddleware and so must be added to the request execution.
Read more >
Routing in ASP.NET Core
Discover how ASP.NET Core routing is responsible for matching HTTP requests and dispatching to executable endpoints.
Read more >
Understanding your middleware pipeline in .NET 6 with the ...
In this post I introduce the Microsoft.AspNetCore.MiddlewareAnalysis package and show how to use it to visualise the middleware in your .
Read more >
Fix: EndpointRoutingMiddleware matches endpoints setup by ...
Fix : EndpointRoutingMiddleware matches endpoints setup by EndpointMiddleware and so must be added to the request execution pipeline before ...
Read more >
Hiding Endpoints From Swagger Documentation in Spring ...
Let's have a look at how we can hide endpoints from Swagger API ... to set the hidden property to true to make...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found