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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With