.Net Core中文編碼問題整理

來源:互聯網
上載者:User

標籤:oid   read   添加   window   自己   mic   trie   cat   images   

1..Net Core Console控制台程式

在.Net Core中預設System.Text中不支援CodePagesEncodingProvider.Instance,

System.Text.Encoding.CodePages.dll允許訪問.Net Framework平台上不支援的編碼提供者。

更多參考:

https://msdn.microsoft.com/zh-cn/library/windows/apps/xaml/mt643899

Nuget:

地址:http://www.nuget.org/packages/System.Text.Encoding.CodePages/

命令:

Install-Package System.Text.Encoding.CodePages

使用執行個體:

class Program{    static void Main(string[] args)    {        //註冊編碼提供者        Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);        Console.WriteLine("中文內容");        Console.WriteLine("Hello World!");        Console.Read();    }}

 

2.Asp.Net Core MVC視圖頁面編碼問題

在VS2017中,剛上線的版本,在控制器的Action右鍵》添加視圖,建立的視圖檔案編碼都是ANSII的,預設情況下在瀏覽器中查看中文都是亂碼。

解決方案1:換種添加視圖的方式,在建立項中添加視圖

解決方案2:在VS中建立的視圖修改一下頁面的編碼為UTF-8

檔案》進階儲存項》修改頁面編碼

註:特別說明,預設情況下“進階儲存項”是隱藏的,需要在“自訂”中自己添加,

、

 

更多:

Asp.Net Core MVC控制器和視圖之間傳值

.NetCore中EFCore的使用整理

VS Code搭建.NetCore開發環境(二)

.Net Core中文編碼問題整理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.