I'm working on a commerce platform and want SEO friendly URLs and I have created the following routes
routes.MapRoute(
name: "Common",
template: "{generic_se_name}",
defaults: new { controller = "Common", action = "Show" }
);
routes.MapRoute(
name: "Product",
template: "{productName}",
defaults: new {controller = "Product", action = "Show"}
);
routes.MapRoute(
name: "Category",
template: "{categoryName}",
defaults: new { controller = "Catalog", action = "Show" }
);
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
However when I call http://localhost/creme it goes into the common and that's what I expect to happen. In that, i look into the database to figure out if its a product or category and if its a product I do a
public IActionResult Show(string generic_se_name)
{
var type = db.UrlRecords.FirstOrDefault(x => x.Slug == generic_se_name);
if (type != null)
{
switch (type.EntityType)
{
case "Product":
return RedirectToRoute("Product", new {productName = generic_se_name });
case "Category":
return RedirectToRoute("Category", new { categoryName = generic_se_name });
}
}
return BadRequest();
}
But it keeps calling Common route even thou I say it should redirect to Product Route.
What am I doing wrong?
Regards Klaus