ASP.NET MVC - hiding id in URL?
- by mcfroob
I'm building a basic blog application just now, for viewing data I'm just using the default route, i.e. -
routes.MapRoute
(
"Default", // Route name
"{controller}/{action}/{id}",
new { controller = "Blog", action = "Index", id = UrlParameter.Optional }
);
So that when you go to mysite.com/View/12 it displays the blog with id 12. I want to modify the URLs so that they look as follows: mysite.com/View/2010/06/01/this-is-the-title.
I could have a URL mapping like -
routes.MapRoute(
"View",
"View/{year}/{month}/{day}/{title}",
new { controller = "Blog", action = "View" }
);
But then I'm not passing the ID into the Controller action so I would have to search on the date and title which doesn't feel right. On the other hand, if I pass the ID in it will show up in the URL which isn't what I'm aiming for either. Is there any way to redirect to the URL I want in the controller action after passing only the ID in as a paramter, or to pass the ID into the a Map Route but hide it in the URL?
Thanks for your help!