Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC: How to force all links to goto 1 page?

I am trying to figure out how i can create a route configuration so that all URLS will goto the same VIEW (Page).

CUrrently of course if i do for example

/Products/Id

Then this would look in the Products controller.

I would like to always goto my MainController and the same action no matter what the URL is

Is this possible?

Thanks in advance

like image 551
Martin Avatar asked Sep 25 '12 08:09

Martin


1 Answers

This is possible to be done with a catchAll route:

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        "CatchAll",
        "{*url}",
        new { controller = "Main", action = "Index" }
    );
}

Alternatively you could have your default route and put the catchAll route after it so that if no other route is matched, the catchAll route will get it

like image 177
Darin Dimitrov Avatar answered Sep 24 '22 17:09

Darin Dimitrov