8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ASP.Net Core + Razorで日本語がエスケープされないようにする

Last updated at Posted at 2016-07-07

#結論

Startup.cs に以下の記述を加える

using System.Text.Encodings.Web;
using System.Text.Unicode;

public void ConfigureServices(IServiceCollection services) {
    services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.BasicLatin,
                                             UnicodeRanges.CjkSymbolsandPunctuation,
                                             UnicodeRanges.Hiragana, 
                                             UnicodeRanges.Katakana,
                                             UnicodeRanges.CjkUnifiedIdeographs));
    // その他 .AddMvc() など...
}

#解説

デフォルトではHtmlEncoder.Defaultが使われ、これがU+0000..U+007F以外は全てエスケープする設定になっている。
そこでDIにて日本語も許容するように設定した物を突っ込む。
必要に応じて他のコード範囲も加える事が可能。

CoreFxのソースを参照。

8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?