Question

I have a case where MVC's routing (mapping a url to a controller) is just getting in the way. I want to circumvent it and send all urls to a single controller (no matter the format and without any attempt to parse them).

I assumed this would be easy, but I'm stuck. Help is much appreciated.

Was it helpful?

Solution

Write a catch-all route (global.asax) and define a default action/controller to this route..

routes.MapRoute(
            "All",
            "{*all}",
            new { controller = "Home", action = "Index" }
        );

OTHER TIPS

Adding this to Application_Start in Global.asax.cs should work:

RouteTable.Routes.MapRoute(null, "{*path}", new { controller = "MyController", action = "MyAction" });

The parameter to MyAction should be called path.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top