I'm really having a hard time getting my head around routing. This has probably been asked before but I couldn't find it or didn't ask the right way...
I am porting over an existing classic asp site and beginning by adding an admin dashboard. What I need is for when a user simply enters the site name the default document (default.asp) gets loaded, however if they enter {site}/Admin then routing takes over. My default route controller is called "AdminController" and I have my project set up to start in /Admin. This works, but anything else doesn't, unless I fall back to the basic default route that comes with a new project.
Desires:
- {site} -> {site}/default.asp
- {site}/Admin -> Admin/Index action
- {site}/Admin/Shops -> Shops/Index action
- {site}/Admin/Shops/Edit/{id} -> Shops/Edit(id) action
Here is my routing, I'm stuck somewhere:
public static void RegisterRoutes(RouteCollection routes)
{
routes.RouteExistingFiles = true;
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"EditShop", // Route name
"Shops/Edit/{slug}", // URL with parameters
new
{
controller = "Shops",
action = "Edit",
slug = ""
} // Parameter defaults
);
routes.MapRoute(
"Shops", // Route name
"Admin/Shops/", // URL with parameters
new
{
controller = "Shops",
action = "Index"
} // Parameter defaults
);
// default route for this app
routes.MapRoute(
"Admin", // Route name
"Admin/", // URL with parameters
new { controller = "Admin", action = "Index" } // Parameter defaults
);
// default route for this app (this works for all cases except default.asp)
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Admin", action = "Index", id = UrlParameter.Optional }
);
route开发者_运维知识库s.MapRoute("NothingMatched", "{*url}",
new {controller = "Error", action = "Http404"});
}
I see you mapped the EditShop to Shops/Edit. That should probably be mapped to Admin/Shops/Edit to achieve what you want. I don't see any problem with the other route, but I could be wrong.
精彩评论