You can also look into this example that explains the ASP.NET routing. The ASP.NET Routing module is responsible for mapping incoming browser requests to particular MVC controller actions.
nopCommerce follows the IRouteProvider interface which is used for route registration during application start-up. All core routes are registered in the RouteProvider class located in the Nop.Web project.
In your project, open RouteProvider.cs - You will find this file in this location: Nop.Web/Infrastructure/RouteProvider.cs
using
System.Web.Mvc;
using
System.Web.Routing;
using
Nop.Web.Framework.Localization;
using
Nop.Web.Framework.Mvc.Routes;
namespace
Nop.Web.Infrastructure
{
public
partial
class
RouteProvider : IRouteProvider
{
public
void
RegisterRoutes(RouteCollection routes)
{
//We reordered our routes so the most used ones are on top. It can improve performance.
//home page
routes.MapLocalizedRoute(
"HomePage"
,
""
,
new
{ controller =
"Home"
, action =
"Index"
},
new
[] {
"Nop.Web.Controllers"
});
You can create different RouteProvider classes according to your requirements like:
- Creating a new page (see this article)
- Plugins using custom routes
Here are a few examples on how RouteProvider classes have been created for registering various routes.
//widgets
//we have this route for performance optimization because named routes are MUCH faster than usual Html.Action(...)
//and this route is highly used
routes.MapRoute(
"WidgetsByZone"
,
"widgetsbyzone/"
,
new
{ controller =
"Widget"
, action =
"WidgetsByZone"
},
new
[] {
"Nop.Web.Controllers"
});
//login
routes.MapLocalizedRoute(
"Login"
,
"login/"
,
new
{ controller =
"Customer"
, action =
"Login"
},
new
[] {
"Nop.Web.Controllers"
});
//register
routes.MapLocalizedRoute(
"Register"
,
"register/"
,
new
{ controller =
"Customer"
, action =
"Register"
},
new
[] {
"Nop.Web.Controllers"
});
Hope it helps!