user1662812
user1662812

Reputation: 2601

How to catch-all URLs with MapHttpRoute

In addition to all the defined api routes, I want to handle any other url in a LegacyUriRedirect action.

I have tried to leave the routeTemplate empty, but it catches only the root url and ignores any urls with segments.

How do I change the below code so that it catches all urls with any segments?

 config.Routes.MapHttpRoute(
                name: "LegacyUriRedirect",
                routeTemplate: "",
                defaults: new { controller = "URI", action = "LegacyUriRedirect" }
    );

Upvotes: 4

Views: 1552

Answers (1)

user1662812
user1662812

Reputation: 2601

config.Routes.MapHttpRoute(
        name: "LegacyUriRedirect",
        routeTemplate: "{*catchall}",
        defaults: new { controller = "URI", action = "LegacyUriRedirect" }
    );

Upvotes: 5

Related Questions