ASP.NET MVC结肠网址 [英] ASP.NET MVC Colon in URL
问题描述
我见过的IIS有让冒号到URL中的一个问题。我也看到了别人的建议提供了 href=\"http://stackoverflow.com/questions/667429/using-a-colon-in-a-url-with-asp-net-iis\"> 。
I've seen that IIS has a problem with letting colons into URLs. I also saw the suggestions others offered here.
随着我工作的网站,我希望能够通过电影,书籍等的标题,进入我的网址,包括结肠癌,像这样的:
With the site I'm working on, I want to be able to pass titles of movies, books, etc., into my URL, colon included, like this:
mysite.com/Movie/Bob:The Return
这会被消耗掉我的 MovieController
,例如,作为一个字符串,并进一步用于向下行。
This would be consumed by my MovieController
, for example, as a string and used further down the line.
我意识到,一个冒号不理想。没有人有任何其他建议?至于可怜的,因为它是目前,我正在做一个查找和替换所有冒号(:)另一个字符,然后向后更换时,我想使用它的控制器端。
I realize that a colon is not ideal. Does anyone have any other suggestions? As poor as it currently is, I'm doing a find-and-replace from all colons (:) to another character, then a backwards replace when I want to consume it on the Controller end.
推荐答案
网址编码和解码你的电影标题。
您想最终 foo.com/bar/Bob%58The%20Return
作为替代方案,可考虑利用一个<一href=\"http://$c$c.google.com/p/stack-exchange-data-explorer/source/browse/App/StackExchange.DataExplorer/Helpers/HtmlUtilities.cs?r=edb08c0948299b1e74074e09ca5e0b3253797105\"相对=nofollow> HTML帮助删除URL不友好的字符在URL中(方法是 URLFriendly()
)。一个冒号和一个占位符(如破折号)之间的搜索引擎优化的好处很可能是微不足道的。
As an alternative, consider leveraging an HTML helper to remove URL unfriendly characters in URLs (method is URLFriendly()
). The SEO benefits between a colon and a placeholder (e.g. a dash) would likely be negligable.
这篇关于ASP.NET MVC结肠网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!