I am trying to understand how MVC routing works, but it seems I got lost along the way.
I have defined two routes in the Global.asax file as follows
routes.MapRoute("Public", "Public/{controller}/{action}", new { controller = "Home", action = "Index" });
routes.MapRoute("ShopSchema2", "Shop/OldAction", new { controller = "Home", action = "Index" });
My questions—which may be pretty simple:
- When I type
"~/Public/Account/Register", it goes to theAccountcontroller with theRegisteraction. Why the 1st segment(Public) is not taken as value for controller? - When I type
"~/Shop/OldAction", it goes to theHomecontroller with theIndexaction. please describe. - Does the routing system takes the first segment as controller and the second segment as action by default?
- Does the routing system take anything we mention within
{and}in the URL pattern as segment variables.