ASP.NET 4.0 URL Rewriting: How to deal with the IDs

前端 未结 1 1064
囚心锁ツ
囚心锁ツ 2021-01-14 12:15

I have just started adding the new .NET 4.0 URL Rewriting into my project. I have a question.

Let\'s say I have a Article.aspx that displays, well, articles. I made

相关标签:
1条回答
  • 2021-01-14 12:54

    There is nothing to prevent you from including both the ID (for quick SQL retrieval) and the article's title in the link (for SEO purposes). This is exactelly how stackoverflow is handling the routing (check the address for this question).

    routes.MapPageRoute("article-browse", "article/{id}/{title}", "~/Article.aspx");
    

    Obviously, the title after the ID is not necessary to display the page (you only use the ID to fetch the article), but everytime you generate the link in your site, generate it with the title, and the bots will use that when indexing your pages.

    Oh, and you might also want to create a method that translates your title into a URL-friendly string.Like making all lowercase, converting spaces and other characters to '-',etc.

    0 讨论(0)
提交回复
热议问题