Reputation: 7301
I'm trying nopcommerce for the first time. While exploring it, I found that there is an url http://localhost:15536/apple-macbook
where apple-macbook is a product name.
I am wondering how such dynamic routing is done. May I get any idea?
Upvotes: 0
Views: 228
Reputation: 1040
Back nopCommerce 3.9 you will find the route definition for this here
.../Nop.Web/Infrastructure/GenericUrlRouteProvider.cs
routes.MapGenericPathRoute("GenericUrl",
"{generic_se_name}",
new {controller = "Common", action = "GenericUrl"},
new[] {"Nop.Web.Controllers"});
.MapGenericPathRoute() can be found in .../Nop.Web.Framework/Seo/GenericPathRouteExtensions.cs
This GenericPathRoute will lookup the database (UrlRecord table) and if something matches the request it redirects the request to the controller of the entity that was found.
In your case, this would mean a redirect to
case "product":
{
data.Values["controller"] = "Product";
data.Values["action"] = "ProductDetails";
data.Values["productid"] = urlRecord.EntityId;
data.Values["SeName"] = urlRecord.Slug;
}
With the above RouteData the ProductDetails action on the ProductController gets called.
Upvotes: 1