我想开发的URL看起来像如下:创建搜索引擎友好的URL在ASP.NET MVC
http://mysite.com/products/1/best-product-in-the-world
,所有我需要得到适当的记录是以下路线:
http://mysite.com/products/1
当我将产品说明片段添加到URL(“最佳产品”)时,我得到了URL编码问题。我试着在ActionLink的(...)构建自己的网址的这一部分时使用Server.UrlEncode:
<%= Html.ActionLink(item.Subject, "../Post/Detail",
new { id = item.ID,
descriptiveUrl = Server.UrlEncode(Product.ShortDescription) },
new { rel = "canonical",
title = Product.ShortDescription,
@class = "product-hyperlink" })%>
但这使得特殊字符和空格定期编码的元素,就像下面:
http://localhost:2392/Products/Detail/1/best+product+in+the+world253f
...它创建了一个400,不好的请求异常。我不确定我是否做了正义的问题,但如果需要的话可以提供进一步的澄清。
更新:这篇文章的网址如下,我试图做一些非常相似的事情!
http://stackoverflow.com/questions/1148955/creating-search-engine-friendly-urls-in-asp-net-mvc
我想你是对的。这里是另一个问题提出相同的问题(http://stackoverflow.com/questions/217960/how-can-i-create-a-friendly-url-in-asp-net-mvc)。我想我想确保我生成一个URL安全的“slug”。 – jn29098 2009-07-19 00:41:54