I have a MVC 5 app in ASP.Net targeting .Net 4.5 that has a mix of views(.cshtml) and webforms (.aspx). The app compiles successfully and even renders the starting view in browser. However, a link generated by Html.ActionLink
in starting view is using the first route in the routing table when it should be using the third route. I am confused why Html.ActionLink
uses the first route.
I have two webforms called WebForm1.aspx and Webform2.aspx. Each of these webforms have a route assigned.
Question
Why is Html.ActionLink using the first route in my routings table and not the third route?
My Routings Table
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
//routes for webforms below
routes.MapPageRoute("webform1", "routeexample", "~/WebForm1.aspx", true);
routes.MapPageRoute("webform2", "routeexample2", "~/WebForm2.aspx", true);
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
//routes for MVC views below
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
Markup for ActionLink
<li>@Html.ActionLink("Home", "Index", "Home")</li>
Generated output by above markup
https://localhost:44394/routeexample?action=Index&controller=Home
Expected output of above markup using the third route from routings table
https://localhost:44394 OR https://localhost:44394/Home/Index