Developer forum

Forum » CMS - Standard features » Encoding issue in cshtml files

Encoding issue in cshtml files

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi there,

I have a template that contains Icelandic, like this:

When I open the file on the server with Notepad++ the code looks as above which is as it should.

When I then open the template in the template editor in the Dynamicweb backend, it gets corrupted and looks like this:

If I then save the template, the text above gets written to the cshtml file as-is, effectively breaking the template.

When examining the file in Notepad++ again on the server I can see the encoding has switched from UTF-8 to UTF-8-BOM.

Not sure if it's related, but when I compare our web.config with the one from a standard DW application, our config file is UTF-8-BOM as well, whereas the standard one is UTF-8.

Any idea why this is happening and what I can do about it?

Thanks!

Imar

 


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Do not use UTF8 BOM encoding in your web.config? BOM is 'old days' - from before UTF8 and not needed in UTF8 encoded files according to unicode.org - they recommend not using it.

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Yes, agreed about UTF-8 BOM. I don't know how we got there though; may have been incorrectly saved at some point; it certainly wasn't on purpose. I'll revert the config file to UTF8 and see if that fixes the template save issue.

Thanks!

Imar

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

I saved the web.config file as UTF and recycled the site. Yet when I open the template in the editor. the text is wrong again. If I don't save and download the file, it opens correctly in Notepad++ and shows UTF-8 not UTF-8-BOM as the encoding.

All references in web.config to encoding are UTF-8 also.

What am I missing? Should this work out of the box with Icelandic?

Imar

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

I've attached a template that shows the behavior. Just open it in the editor and it becomes messed up. I tested this an another site (9.14) and it has the same behavior.

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply
This post has been marked as an answer

Hi Imar,

I was able to reproduce the issue and have registered it as bug #10795
Apparently we use Encoding.Default when reading text files and that sure messes things up.
I have changed it to use UTF8 instead. Fix is on the way.

/Morten

Votes for this answer: 1
 
Kristian Kirkholt Dynamicweb Employee
Kristian Kirkholt
Reply
This post has been marked as an answer

Hi Imar

The Encoding issue when reading files (Bug#10795) has been fixed in Dynamicweb version 9.14.4

Get this from the download section https://doc.dynamicweb.dk/downloads/dynamicweb-9

Sorry for any inconvenience this may have caused

Kind Regards
Care Support
Kristian Kirkholt

Votes for this answer: 1
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Excellent, thank you both!

 

You must be logged in to post in the forum