Wednesday, April 3, 2013

Mix of character encoding on a web page

I recently experienced a weird error with encoding while working on an Umbraco site. The page would show some special chars correct and some not. The pattern was that chars in the template would display wrong, but chars in the (dynamic) content would display correct.

First step was to verify that everything was UTF-8; the HTML header, the template (html) files, the (html) partial files etc. Then check that all config settings were set to UTF-8; web.config and umbracoSettings.config.

Still didn't work. I also tried manually switching encoding in chrome (tools->encoding) but it still didn't work.

The fix:
I needed to add the fileEncoding attribute to the globalization tag in web.config

before:
<globalization requestEncoding="UTF-8" responseEncoding="UTF-8" />

after:

<globalization requestEncoding="UTF-8" responseEncoding="UTF-8" 
fileEncoding="UTF-8" />


Ah, well...