views:

845

answers:

7
+1  Q: 

HtmlEncode UTF-8

I'm using Server.HtmlEncode on a utf-8 string in asp-classic, which works fine until there are some accents in the string e.g. Rüstü Recber, which appears as Rüstü Recber (Rüstü Recber in the source).

I've tried setting the Response.Charset property to utf-8 but this doesn't make any difference.

A: 

Check if the editor you are using to view the text is set to show utf-8.

Lucia
A: 

@lucia

I'm currently using Scite as my text editor (encoding set to utf-8) and the characters are showing up correctly.

The same problem occurs if I'm displaying text from a database.

Mr Plough
A: 

Did you try to UrlEncode as well?

dove
A: 

@dove

Server.UrlEncode renders in the page (and the source) as R%C3%BCst%C3%BC+Recber.

Mr Plough
A: 

Are you sure that the string is correct before it is passed to HtmlEncode ? It looks like the string might be encoded wrong before it is passed to HtmlEncode.

Try to encode a string that you know is correct, and see if it is encoded correctly.

JacquesB
A: 

@olavk

I've tried the Iñtërnâtiônàlizætiøn test string from Survival guide to i18n and have the same problem i.e. it shows up as Iñtërnâtiônàlizætiøn without HtmlEncode, but Iñtërnâtiônà lizætiøn with.

I've also used the online version of Iconv to check the encoding of the file and it comes out as 'UTF-8 Unicode text, with CRLF line terminators'

Mr Plough
+1  A: 

Update (Solved): Adding <%@CODEPAGE=65001%> at the start of the page corrected the problem (http://technet.microsoft.com/en-us/library/bb742422.aspx)

Many thanks for all of the suggestions.

Mr Plough