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

若如初见. 提交于 2021-01-27 01:08:21

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!