防止显示%20之类的URL中的空格 [英] Prevent spaces in URL showed like %20

查看:117
本文介绍了防止显示%20之类的URL中的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在地址栏中显示漂亮的URL,并避免显示%20之类的空格

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

这里是一个例子:

是否可以将这些空格替换为破折号?

Is it possible to replace these spaces with a dash ?

类似:/BANQUE/International-Ledger

Something like: /BANQUE/International-Ledger

也许在路由中要做些什么?

Maybe something to do in the routing ?

谢谢.

推荐答案

您不想替换生成的路由中的空格,而不想首先生成它们.

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

您的国际分类帐"是什么?如果是动作,则使用[ActionName("International-Ledger")]

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

如果它是某种产品或产品类别,那么优良作法是不使用产品名称作为URL,而是从名称中生成一些令牌",例如,用正则表达式,用破折号替换空格,用其基本字符替换特殊字母字母变体,也许还有一些唯一的标识符,以防止具有相同名称的产品发生冲突.

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.

请参见如何我是从字符串创建SEO友好的短划线分隔网址吗?

这篇关于防止显示%20之类的URL中的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆