URL 中的特殊字符被替换
我正在为客户的主页创建一个动态产品列表,我在 IE8 中发现了一个非常烦人的问题。
产品的 URL 采用以下结构构建:
http://www.domain.com/language/category/product_name.aspx
当我以西班牙语显示网站并且类别包含特殊字符 "ñ"
时,会出现问题:IE 将该字符替换为 " %c3%b1"
。
按照我的代码,我发现 URL 的构造正确,但是当服务器显示结果页面时,所有包含特殊字符的 URL 都已被替换。
aspx 页面具有控件:
<asp:HyperLink ID="LinkTitle" runat="server">Product Name</asp:HyperLink>
并且类后面的代码在 ListView 的 ItemDataBound 事件期间将值分配给控件
Dim L_LinkTit As HyperLink
Dim Link as String
L_LinkTit = LstView.FindControl("LinkTitle")
Link = "/" & Session("lang") & "/" & cat & "/" & product & ".aspx"
L_LinkTit.NavigateUrl = Link
关于如何解决此问题有任何想法吗?
I'm creating a dynamic list of products for a client's homepage, and I've found a very annoying issue in IE8.
The products' URLs are built with the following structure:
http://www.domain.com/language/category/product_name.aspx
The problem appears when I'm displaying the site in Spanish and the category contains the special character "ñ"
: IE replaces the character with "%c3%b1"
.
Following my code I've found that the URLs are constructed properly, but when the server shows the results page all the URLs cointaining special characters have been replaced.
The aspx page has the control:
<asp:HyperLink ID="LinkTitle" runat="server">Product Name</asp:HyperLink>
and the code behind class assigns the value to the control during a ListView's ItemDataBound event
Dim L_LinkTit As HyperLink
Dim Link as String
L_LinkTit = LstView.FindControl("LinkTitle")
Link = "/" & Session("lang") & "/" & cat & "/" & product & ".aspx"
L_LinkTit.NavigateUrl = Link
Any ideas on how to resolve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是设计使然。
网址只能包含一组仅 ASCII 字符。任何超出 ASCII 的字符都在内部进行百分比编码。
现代浏览器、搜索引擎等会在显示 URL 之前对其进行百分比解码(因此看起来更好),但在内部, UTF-8
ñ
将始终为%c3%b1
。 IE8 显然不会这样做,因此如果您想提供正确的 URL,则无法使它们在 IE8 中看起来不错。有关背景信息,请参阅URL 中的 Unicode 字符。
That's by design.
URLs can contain a set of ASCII characters only. Any characters beyond ASCII are percent-encoded internally.
Modern browsers, search engines etc. will percent-decode the URL before showing it (so it looks nicer), but internally, an UTF-8
ñ
will always be%c3%b1
. IE8 apparently doesn't do this so if you want to serve proper URLs, there is no way to make them look nice in IE8.See Unicode characters in URLs for background information.
最后我成功解决了特殊字符问题。我在网站上做了一些更改。我已经替换了 aspx 页面的 asp HyperLink 控件
,现在后面的代码有点不同现在
IE8 处理所有 URL
Finally I've managed to solve the special characters problem. I made some changes on the website. I've replaced the asp HyperLink control of the aspx page with
and the code behind is a little different now
Now IE8 handles all the URLs