I have a controller with a name MetricsControllerwith one action:
public class MetricsController
{
public ActionResult GetMetrics(int id, string period)
{
return View("Metrics");
}
}
I want to redirect calls to this controller as follows:
http://mysite/metrics/getmetrics/123/24h
I mapped an additional route in mine Global.asax.csas follows:
routes.MapRoute(
"Metrics",
"{controller}/{action}/{id}/{period}",
new { controller = "Metrics", action = "GetMetrics", id = 0, period = "" }
);
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
I just added this to the default template project that Visual Studio 2010 creates.
When I launch the application, instead of using the default HomeController, it starts with MetricsController.
Why is this happening? There is nothing in the url when I run the application that matches the url pattern specified in the route Metrics.
All this is verified in Visual Studio 2010 using the integrated web server.