1

I'm trying to build a file sharing website using MVC. One of the nice to have features are short URL's - Typically in the format such as:

http://site.com/Rtravf2
http://site.com/XddsvgF
http://site.com/AaraEwq

The "actions" at the end of the URL's are in fact Ids which is used to download a file. Urls in this format can all be mapped to the same action method in the home controller, called Download.

Here's the one and only route in my routes table

routes.MapRoute(
    "Default", // Route name
    "{action}/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);

What kind of route should i construct so those Urls can be mapped to the Download action on the Home Controller.

Currently getting a bunch of 404's (naturally!)

Thanks for any pointers.

Fixer
  • 5,985
  • 8
  • 40
  • 58
  • possible duplicate http://stackoverflow.com/questions/1019906/asp-net-mvc-dynamic-routes-and-action-links-with-arbitrary-depth – BobRock Jun 01 '12 at 10:34
  • bobrock, tho perhaps a duplicate, only a single non-conventional answer given in reponse to that question, so question has validity i feel – jim tollan Jun 01 '12 at 10:37

1 Answers1

0
routes.MapRoute(null, // Route name
    "{id}", // URL with parameters
    new { controller = "Home", action = "Download" }
);

routes.MapRoute(null, // Route name
    "Index/{id}", // URL with parameters
    new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
danludwig
  • 46,965
  • 25
  • 159
  • 237