Skip to content

ASP.NET Core 3.0 catch-all route unexpected behavior #16579

Closed
@ExileLee

Description

@ExileLee

Describe the bug

Recently i encounter some unexpected issue

I'm using ASP.NET Core 3.0 and i defined two routes in StartUp.cs

StartUp.cs

   app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllerRoute(
            name: "file",
            pattern: "{controller=File}/folder/{*path}",
            new { Action = "Folder" });

        endpoints.MapControllerRoute(
            name: "default",
            pattern: "{controller=File}/{action=Index}/{filename}");
    });

FileController.cs

public class FileController : Controller
{
    public IActionResult Folder(string path)
    {
        return Ok(path);
    }

    public IActionResult Index(string filename)
    {
        return Ok(filename);
    }
}

request to file/folder/abc/abc i expected to match first route but the result was 404 not found

but if i changed order of route

   app.UseEndpoints(endpoints =>
    {
        endpoints.MapControllerRoute(
            name: "default",
            pattern: "{controller=File}/{action=Index}/{filename}");

        endpoints.MapControllerRoute(
            name: "file",
            pattern: "{controller=File}/folder/{*path}",
            new { Action = "Folder" });
    });

It work!

Expected behavior

My questing is why first version don't work if i defined {controller=File}/folder/{*path} on top

I thought it will check route table sequentially

Metadata

Metadata

Assignees

Labels

area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesbugThis issue describes a behavior which is not expected - a bug.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions