Prevent spaces in URL showed like %20

坚强是说给别人听的谎言 提交于 2019-12-10 19:00:53

问题


I would like to display nice URL in address bar and avoid spaces to display like %20

Here is an example:

Is it possible to replace these spaces with a dash ?

Something like: /BANQUE/International-Ledger

Maybe something to do in the routing ?

Thanks.


回答1:


You dont want to replace spaces in generated route, you want to not generate them in the first place.

What is your "International Ledger" ? If it is action, then use [ActionName("International-Ledger")]

If it is some kind of product or category of product, is it good practice dont use product name for URL, but some "token" generated from name, for example with regex, replacing spaces with dashes, special letters with theirs basic alphabet variants, and maybe some unique identifier to prevent conflicts of products with the same name.

see How can I create a SEO friendly dash-delimited url from a string?



来源:https://stackoverflow.com/questions/8110518/prevent-spaces-in-url-showed-like-20

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!