Reputation: 1325
I want to change the Default page mydomain.com/Views/Home/Index.chtml
of an MVC application to point to another Default page in the application root mydomain.com/Default.aspx
.
This is the default configuration of the MVC Default MapRoute. How can I change the configuration to point to mydomain.com/Default.aspx
? I'm new to MVC and I'm trying to understand how the RegisterRoutes function works.
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
Upvotes: 0
Views: 3156
Reputation: 640
You have to set route config .
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Admin", action = "Index", id = UrlParameter.Optional }
).DataTokens.Add("area", "AdminMaster");
Here AdminMaster is Area , Conttroller Name is Admin and Action Name is Index . If your default page in another Area , then you have to specify Area also .
Thanks .
Upvotes: 0
Reputation: 23
Well I think more cleaner and correct way to do is to migrate your aspx page to a cshtml view and add this as a default route to your route.config
Otherwise a workaround is to redirect from the default route to aspx page.
Have a look at Scott's blog here
Upvotes: 0
Reputation: 21191
From URL Rooting in ASP.NET (Web Forms) - chsakell's Blog, add this before the default MVC route:
routes.MapPageRoute("default", "", "~/Default.aspx");
You could also probably accomplish this using a filter, but it might be easiest just to do a redirect in the Index
action of the HomeController
.
public class HomeController : Controller
{
public ActionResult Index()
{
return Redirect("~/Default.aspx");
}
}
Upvotes: 1