Closed
Description
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