Using "page" route parameter in convention routing fails with Asp.Net Core Mvc 2.0 #6660
Description
I have a website that was working perfectly fine in .NET core 1.1.
Today -- with the release of .NET Core 2.0 -- I decided to update my application. I changed my Target Framework to .NET Core 2.0, and switched over to using the Microsoft.AspNetCore.All package as outlined here: https://blogs.msdn.microsoft.com/webdev/2017/08/14/announcing-asp-net-core-2-0/
I installed the .NET Core 2.0 Runtime on my server. I restarted my server.
The application builds fine, but when I deploy, it seems my routes -- which worked perfectly in .NET Core 1.1 -- no longer work.
When I try using https://example.com/history (desired URL, which the route SHOULD direct to the "History" action of the "Pages" controller) it complains of a missing View.
If I use https://example.com/pages/history (not desired URL) it loads the home page, not the history page.
Again, this worked fine in .NET Core 1.1
This is my /Program.cs:
using Microsoft.AspNetCore.Hosting;
using System.IO;
namespace Framework
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
}
This is the portion of my /Startup.cs with the routes defined at the end:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "404",
template: "404/{id}",
defaults: new { controller = "Pages", action = "Error404"}
);
routes.MapRoute(
name: "news",
template: "news/{page}",
defaults: new { controller = "Pages", action = "News", page = 1 }
);
routes.MapRoute(
name: "history",
template: "history/{page=1}/{sortFilter?}/{sortOrder?}",
defaults: new { controller = "Pages", action = "History"}
);
routes.MapRoute(
name: "restoration-resources",
template: "restoration-resources/{page=1}/{sortFilter?}/{sortOrder?}",
defaults: new { controller = "Pages", action = "RestorationResources"}
);
routes.MapRoute(
name: "vehicles",
template: "vehicles/{vehicle?}/{page=1}/{sortFilter?}/{sortOrder?}",
defaults: new { controller = "Pages", action = "Vehicles" }
);
routes.MapRoute(
name: "gallery",
template: "gallery/{gallery?}",
defaults: new { controller = "Pages", action = "Gallery" }
);
routes.MapRoute(
name: "rss",
template: "rss/{source?}/{post?}",
defaults: new { controller = "Pages", action = "RSS"}
);
routes.MapRoute(
name: "pages",
template: "{action}/{id?}",
defaults: new { controller = "Pages", action = "News"}
);
routes.MapRoute(
name: "default",
template: "{controller}/{id?}",
defaults: new { controller = "Pages", action = "News"}
);
});
}
}
}