0

I need use a specific encoding name. In asp.net I used to do it like this:

var enc = Encoding.GetEncoding("windows-1255");
var name = HttpUtility.UrlEncode("ישראל" ,enc)

How can I achieve the same in asp.net-core? I was trying to use:

WebUtility.HtmlEncode()

but it does not accept the encoding name in its signature.

Eyal
  • 4,653
  • 9
  • 40
  • 56

1 Answers1

0

This works for me.

  1. Install the System.Text.Encoding.CodePages package:

    dotnet add package System.Text.Encoding.CodePages
    
  2. After dotnet restore, use

    var enc = CodePagesEncodingProvider.Instance.GetEncoding(1255);
    var name = System.Web.HttpUtility.UrlEncode("ישראל", enc);
    

Adopted from this answer.

kennyzx
  • 12,845
  • 6
  • 39
  • 83