I have asp.net MVC 4 site which the articles url is : www.site.com/article/623/friendly-url-here
I wan't that if someone accessing an article without the friendly url, it will be completed without redirecting and accessing the database twice (which will make the page load slower).
now:
Entering www.site.com/article/623 -> enter to www.site.com/article/623
as I want it to be:
Entering www.site.com/article/623/the-article-nice-url
(Note the the-article-nice-url being added)
UPDATED:
Route as I use in RouteConfig:
// Articles
routes.MapRoute(
name: "Articles",
url: "articles/{articleId}/{friendlyUrl}",
defaults: new { controller = "PageManagement", action = "ViewArticle", articleId = UrlParameter.Optional, friendlyUrl = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
Page metadata as I use to store the data with DbContext:
public class PageMetadata
{
[Key]
public int Id { get; set; }
public string RepresentationString { get; set; }
public DateTime CreationDate { get; set; }
public DateTime LastUpdateDate { get; set; }
public bool IsVisible { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public string Link { get; set; }
}