问题
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.
回答1:
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>
来源:https://stackoverflow.com/questions/24431985/how-do-i-make-razor-read-utf-8-files-without-bom