Where is HtmlEncode in Asp.NET 5

Keith Hill picture Keith Hill · Nov 25, 2015 · Viewed 12.3k times · Source

I have a custom IHtmlHelper extension method that uses TagBuilder and returns an HtmlString. I can no longer pass tagBuiler.ToString() to the HtmlString constructor as that just returns the typename now.

I see I can use the tabBuiler.WriteTo(TextWriter, IHtmlEncoder) method but I don't know exactly how to get my hands on an object that implments IHtmlEncoder. I see encoders in both System.Text.Encodings.Web and Microsoft.Framework.WebEncoders. But the types in the two namespace don't seem to play well together.

Answer

Miroslav Holec picture Miroslav Holec · May 23, 2016

In ASP.NET Core RC2 you can find HtmlDecode in System.Net.WebUtility:

In your project.json import dependency system.net.utilities

"dependencies": {
    "System.Text.Encodings.Web": "4.0.0-rc2-24027"
}