A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/dotnet/aspnetcore/issues/16579 below:

ASP.NET Core 3.0 catch-all route unexpected behavior · Issue #16579 · dotnet/aspnetcore · GitHub

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

Lienfa, Popsikill and ExileLee


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4