Reputation: 7504
I've got an ASP.NET MVC site under a Classic ASP site. The MVC site is:
The routes
http://www.inrix.com/traffic
http://www.inrix.com/traffic/home
http://www.inrix.com/traffic/features
work fine. However, the route:
http://www.inrix.com/traffic/support
does not. Click it to see what I'm getting. If I include the action:
http://www.inrix.com/traffic/support/index
it works.
When I run this at home by pressing F5 in VS, it works fine with just http://www.inrix.com/traffic/support (i.e., no action specified). Here are my routes:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Terms",
"{controller}/{id}",
new { controller = "Terms", action = "Index" }
);
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
"ThankYou",
"{controller}/{action}/{email}/{id}"
);
}
www.inrix.com/traffic maps to HomeController (Index action).
I want www.inrix.com/traffic/support to map to SupportController, Index action.
What's going on with the "support" route?
Additional Code:
Controller:
using System.Web.Mvc;
namespace InrixTraffic.Controllers
{
public class SupportController : Controller
{
public ActionResult Index()
{
return View();
}
}
}
View:
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Support</title>
</head>
<body>
<h1>Hello!</h1>
</body>
</html>
New route:
routes.MapRoute(
"Support",
"traffic/support",
new { controller = "Support", action = "Index" }
);
Upvotes: 2
Views: 129
Reputation: 247
@EDIT: I think you have a file path (folder probably) with that same url. I mean, a folder named "support". In order to override file path with route path you need to add:
routes.RouteExistingFiles = true;
Upvotes: 2
Reputation: 1073
Do you have a Traffic controller with an Index action? If so I think you need to set-up a route like whats shown below:
routes.MapRoute(
"Terms",
"traffic/support",
new { controller = "Traffic", action = "Index" }
);
Place this route above your Terms route in your RegisterRoutes method.
EDIT
I would setup my routes like this:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Support",
"traffic/support",
new { controller = "Support", action = "Index" }
);
// don't know why you need the id at the end
routes.MapRoute(
"Terms",
"terms",
new { controller = "Terms", action = "Index" }
);
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
// why does this route not have any defaults defined?
routes.MapRoute(
"ThankYou",
"{controller}/{action}/{email}/{id}"
);
}
Upvotes: 1