URL 编码 - 非法字符替换
我正在我目前正在从事的一个项目中做一些 URL 重定向。我是网络开发新手,想知道删除任何非法路径字符(例如“-”)的最佳实践是什么? 。
我希望我不必手动用编码后的 URL 替换每个字符
我尝试过 UrlEncode 和 HTMLEncode,但 UrlEncode 不适合?并且 HTMLEncode 不适合 '
例如,如果我要使用以下内容:
Dim name As String = "Dave's gone, why?"
Dim url As String = String.Format("~/books/{0}/{1}/default.aspx", bookID, name)
Response.Redirect(url)
我已经尝试像这样包装 URL:
Dim encodedUrl As String = Server.UrlEncode(url)
并且
Dim encodedUrl As String = Server.HTMLEncode(url)
I am doing some URL redirections in a project that I am currently working on. I am new to web development and was wondering what the best practise was to remove any illegal path characters, such as '-? etc.
I'm hoping I don't have to resort to manually replacing each character with their encoded URLs.
I have tried UrlEncode and HTMLEncode, but UrlEncode doesn't cater for the ? and HTMLEncode doesn't cater for '
E.g. If I was to use the following:
Dim name As String = "Dave's gone, why?"
Dim url As String = String.Format("~/books/{0}/{1}/default.aspx", bookID, name)
Response.Redirect(url)
I've tried wrapping URL like this:
Dim encodedUrl As String = Server.UrlEncode(url)
And
Dim encodedUrl As String = Server.HTMLEncode(url)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
URL 规范(RFC 1738,12 '94)提出了一个问题,因为它将 URL 中允许的字符的使用限制为 US-ASCII 字符集的有限子集:
所以我认为您需要担心?,并且在我的系统上
URL Encode; 转换: %7e%2fbooks%2f1%2fDave's+gone%2c+why%3f%2fdefault.aspx
现在,您在使用吗有任何网址重写吗?
The specification for URLs (RFC 1738, Dec. '94) poses a problem, in that it limits the use of allowed characters in URLs to only a limited subset of the US-ASCII character set:
So I think you need to worry about ?, and on my system
URL Encode; converts: %7e%2fbooks%2f1%2fDave's+gone%2c+why%3f%2fdefault.aspx
Now, are you using any url rewriting into this??
尝试以下操作,
我认为它是 HttpUtility.UrlEncodeComponent ,请参阅 msdn 以获取更多信息。
Try following,
I think its HttpUtility.UrlEncodeComponent , please see msdn for further information.