Prasad Krishnarao

Prasad Krishnarao

  • NA
  • 582
  • 16.1k

Routing in ASP.Net MVC - Default

Oct 15 2019 12:50 PM
Hello
 
If  I run the application without Controller name and Action Name, I am expecting the Default Route (Index Action) should be executed.
 
But in my scenario, the Application calls the Contact Action (the first Route). Is that correct?
 
Could you please explain to me?
 
URL: https://localhost:43350/ 
 
 
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "about",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Contact", Id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}


Answers (2)