MVC Routing based on id only

So I had a situation where I wanted to route to a controller based on the id only.  What this means is I want a real short url, like and have it redirect to a controller with the 768345 being the id to pass to that controller.  The way to do this is to add a rout path to my RouteConfig.cs file.  What I did was this.
                name: "Push",
                url: "{id}",
                defaults: new { controller = "LongURL", action = "Index", id = UrlParameter.Optional }
What it does is creates a new route path (I put mine first in the set) that simply looks for 1 parameter and assigns it to ID, then defaults the other items (controller and action) and sends you on your way.

Add comment