0

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?

Dr. Rajesh Rolen
  • 14,029
  • 41
  • 106
  • 178
Cpt. Awesome
  • 87
  • 1
  • 2
  • 13

2 Answers2

5

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.

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • I'm using IE8. But the browser doesn't percent-decode the url. – Cpt. Awesome Feb 21 '12 at 11:01
  • @Cpt If I paste `http://www.iana.org/domains/example/£óñ` into IE8, it leaves the characters intact. Where are you looking at the URL? In the location bar? Do you have a live example to show? – Pekka Feb 21 '12 at 11:03
  • If I change manually the percent-code to special characters, everything works OK. The error seems to occur during the construction of the list. Here's an example: [link]http://www.motocard.com/sp/productsmoto/renthal/puños-14_199_0_95_0_0.aspx. Look at the links of the list – Cpt. Awesome Feb 21 '12 at 11:12
  • @Cpt indeed. Chrome is converting it into a `ñ`, but IE8 isn't. Even though it *can* deal with directly entered special characters, it doesn't seem to resolve the characters back, I just tried out on another website and it's doing the same thing. My information about IE8 being able to handle this is wrong then. – Pekka Feb 21 '12 at 11:19
  • something inside me was telling me that IE8 was the only responsible for this. Anyway, thanks for your time! I'm going to do some research and try to fix it. If I can solve this weird issue, I'll let you know – Cpt. Awesome Feb 21 '12 at 11:28
  • I have fixed it. I'm not sure this is the best solution, but it will do the trick – Cpt. Awesome Feb 21 '12 at 18:54
0

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

<a id="LinkTitle" runat="server">Product Name</a>

and the code behind is a little different now

Dim ProdLNK As HtmlAnchor
Dim Link as String
ProdLNK = LstView.FindControl("LinkTitle")

Link = "/" & Session("lang") & "/" & cat & "/" & product & ".aspx"
ProdLNK.HRef = Link

Now IE8 handles all the URLs

Cpt. Awesome
  • 87
  • 1
  • 2
  • 13