I have a problem in the file RouteConfig.cs in my asp.net mvc4 application :
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Admin",
url: "Admin",
defaults: new { controller = "Home", action = "Administration" }
);
}
in the home controller :
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
public ActionResult Administration()
{
return View();
}
and added the view :

but when i put http://localhost:61961/Admin as url the view is not found.
Why this happens? how can i fix it?
The Routing config is ordered. please move your administration-Config to the top of RegisterRoutes.
Right now you would be mapped to
Controller: admin
View: index
as your default routing catches your localhost:{port}/admin
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Admin",
url: "Admin",
defaults: new { controller = "Home", action = "Administration" }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With