我已ASP.NET MVC 4個網站,其中的文章網址是:www.site.com/article/623/friendly-url-here友好的URL重定向
我wan't,如果有人訪問沒有文章友好的URL, 將完成沒有重定向和訪問數據庫的兩倍(這將使得網頁加載速度較慢)。
現在:
進入www.site.com/article/623 - >進入到www.site.com/article/623
,因爲我希望它是:
進入www.site.com/article/623/the-article-nice-url
(注意了 - 文章 - 漂亮的URL添加)
更新:
路線,因爲我在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 }
);
頁的元數據,因爲我要用到的數據與的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; }
}
你的路由設置如何? – rickythefox
更新了路由設置 –