views:

459

answers:

4

Is there any problem with ASPX to render french accented characters?

I am using utf-8 to encode.

I never had any problem like this before (but since this is the first time I am working on an ASP server is there any fix?)

e.g Événements = Événements Journées fériées = Journées fériées

Is this an encoding problem? or is there any specific code I need to place to render it correctly.

here is an example

The page reads:

Pour recevoir les communications de l’école par courriel, veuillez nous indiquer votre adresse courriel

It should read:

Pour recevoir les communications de l'école par courriel, veuillez nous indiquer votre adresse courriel
+2  A: 

What's the problem, exactly? Have you set @Codepage=65001 in the page directives at the top of your file? Have you marked the content-type with the correct encoding so that the client knows what its getting?

If you see question marks, it's probable that you haven't set the response code page correctly. If you see two unrelated characters in place of a single character with a diacritic , you haven't told the client what it needs to know to treat the page as UTF-8, e.g.

Response.CodePage = 65001 ;
Response.CharSet = "utf-8" ;

There are slight differences between asp.net and asp handling of encoding, so it would also be helpful if you were more specific about which technology you're using, but that should get you most of the way there.

In ASP.Net, you can set the encoding site-wide in your web.config file, so you can avoid messing with Response.CodePage and Request.CodePage on every page. You still want to mark the Response Charset using the meta http-equiv content-type element in your HTML or using Response.Charset.

<globalization 
            requestEncoding="utf-8" 
            responseEncoding="utf-8"  />

If you don't want to use web.config for this for some reason, you'd use <%@CodePage=65001 %> in your .aspx file before you output any text, in the page directives.

It looks like the page in question contains incorrectly encoded UTF-8. Is the content coming straight from the .aspx file or is it being pulled from a database or something?

JasonTrue
Hi sorry I would like to know how to implement this as I am new to all of this ASP and everytime I try to post it in my source code it gives me a runtime error. I don't know if I am putting it correctly or not in the right position. Let me know. Thanks
kwek-kwek
the content is coming straight from the file, how would I do it?
kwek-kwek
I think your source file is corrupted, then. I see 0a3c703e4a6f75726ec383c2a9657320 in a hex editor, which translates to Journées. Probably you didn't save the original text to utf-8 correctly. Asp.Net is not doing any conversion of literal text. Basically, it looks like you've double-encoded the source file, so that you've taken UTF-8 text, treated it as Windows-1252, and converted the text to UTF-8.
JasonTrue
A: 

Instead of using the actual characters, is there a reason it couldn't be HTML-encoded?

so instead of

Événements

use

&Eacute;v&eacute;nements 

and then it becomes the responsibility of the user's browser to render the characters correctly.

there's a complete list at http://www.w3schools.com/tags/ref_entities.asp

nerdabilly
well this is to make my life easier instead of encoding everything it could just render it to the proper character...
kwek-kwek
There's no good reason to use named entities when you have chosen to use utf-8, except for characters specifically reserved for HTML.
JasonTrue
Using entities would make the source unreadable to a human. In addition, it would significantly increase the file size.
PauliL
A: 

My first thougt was that you do not send the correct headers for utf-8. But using header reader at web-sniffer shows that the headers are correct.

The broblems seems to be that you have converted the text into utf-8 twice.

When I look at the HTML source of your page with Firefox "View Page Source" using ISO-8859-1 encoding, your example text shows as:

Pour recevoir les communications de l’école par courriel, veuillez nous indiquer votre adresse courriel

That is, the 2 non-ASCII characters in the word l'école have been converted into 5 bytes, and those 5 bytes have then been converted again into 12 bytes.

PauliL
A: 

Try using: Server.HTMLEncode(strToShow)

Felipe