Creating Search Engine URLs in ASP.NET MVC

I would like to develop a url that looks like this:

http://mysite.com/products/1/best-product-in-the-world

Where I need to get to the desired record, the following route:

http://mysite.com/products/1

When I add the product description detail to the URL ("the best product in the world"), I get problems with the URL encoding. I tried using Server.UrlEncode when constructing this part of my URL in ActionLink (...):

<%= Html.ActionLink(item.Subject, "../Post/Detail", 
    new { id = item.ID, 
          descriptiveUrl = Server.UrlEncode(Product.ShortDescription) }, 
    new { rel = "canonical", 
          title = Product.ShortDescription, 
          @class = "product-hyperlink" })%>

But it does regular coded elements for special characters and spaces, like the following:

http://localhost:2392/Products/Detail/1/best+product+in+the+world253f

... which creates an exception of 400, is a bad call. I’m not sure that I raised the question of justice, but can provide additional clarifications if necessary.

Refresh : This url looks like this and I'm trying to do something very similar.

http://stackoverflow.com/questions/1148955/creating-search-engine-friendly-urls-in-asp-net-mvc
0
3

, ( ) "slug"; . URI.

, -- .

+2

A standard practice is to store a "slug" with every message that will function as a URL that goes beyond. For example, your slug for the above message would be:

best-product-in-the-world

A decent CMS will do this automatically for you and allow you to configure the filter before saving.

+1
source

All Articles