Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make Razor read UTF-8 files without BOM?

We have separated teams for front end and back end work. The front end is using a large diversity of editors to edit the CSHTML and most of them save UTF-8 without a byte order mark. The problem is, Razor expects a BOM to be present. If it's not present it will read the file using the current code page and we get encoding problems.

How would I make Razor to accept the UTF-8 files without a BOM? Apparently the only solution would be to implement an own VirtualPathProvider and thus also a VirtualFile. Unfortunately, the current used VirtualPathProvider is MapPathBasedVirtualPathProvider, which is an internal class. So I'd have to re-create a lot of functionality.

like image 815
user3779544 Avatar asked Jun 26 '14 13:06

user3779544


1 Answers

Following How to force ASP.NET MVC to read .cshtml files as UTF-8?, try to add this in Web.config:

<system.web>
    <globalization fileEncoding="utf-8" />
</system.web>
like image 164
jkolo Avatar answered Sep 29 '22 02:09

jkolo