7

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

Martin
  • 23,844
  • 55
  • 201
  • 327
  • 1
    this sounds like a terrible idea. – nathan gonzalez Sep 25 '12 at 08:07
  • 1
    Can I ask why, is this for a "This site is under development" page or something like that? – Manatherin Sep 25 '12 at 08:08
  • Yes the reason for this, is AngularJS. It states :- Server side Using this mode requires URL rewriting on server side, basically you have to rewrite all your links to entry point of your application (e.g. index.html) – Martin Sep 25 '12 at 08:48

1 Answers1

20

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

Derek Greer
  • 15,454
  • 5
  • 45
  • 52
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • THis sounds great, yes i know it defeats the object but i am using angularjs on client so i really won't be using views on the server. Well 1 view .. yes :-) – Martin Sep 25 '12 at 08:50
  • Thanks Darin. Your answer helped, and as Martin said, I'm also using AngularJS on the client (on a Single Page architecture), and I want everything to go through the same MVC Controller. – Tiago Reis Jul 14 '13 at 19:38
  • Good answer. One comment though, the boilerplate "Default" route is itself a catch all, so you wouldn't be able to have both. – Derek Greer Jul 14 '14 at 00:40