I'm creating utility pages and the structure of the code files is as below:
/Areas/MyTools/Controllers/UpdateField
/Areas/MyTools/Views/UpdateField/Index.cshtml
When I browse http://mysite/mytools/updatefield, it works fine and I would like to open the same page for http://mysite/mytools/ as well.
Is it done differently in Sitecore?
SOLUTION:
@Hishaam's answer fixed it. Here is all the code for anyone experiencing the same issue.
MinionsAreaRegistration.cs
This class is created in the project, when you add an area. Add a new route in RegisterArea
public class MinionsAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
return "MyTools";
}
}
public override void RegisterArea(AreaRegistrationContext context)
{
context.MapRoute(
"MyTools_default",
"MyTools/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
context.MapRoute(
"MyTools_Home",
"MyTools/{id}",
new { controller = "UpdateField", action = "Index", id = UrlParameter.Optional }
);
}
}
RouteConfig.cs
This class is also created when you add a MVC project. Add a new map route in RegisterRoutes
.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"MyTools_Home",
"MyTools/{id}",
new { controller = "UpdateField", action = "Index", area = "MyTools", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "MyTools_default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
routes.MapRoute( "MyTools", // Route name "MyTools/{id}", // URL with parameters new { controller = "UpdateField", action = "Index", area = "MyTools", id = UrlParameter.Optional } // Parameter defaults );