Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replacement for System.Web.HttpUtility.UrlEncode/UrlDecode ASP.NET 5

I would like to know if there is a replacement for System.Web.HttpUtility.UrlEncode and UrlDecode.

As I found for Encode it should be: Microsoft.Framework.WebEncoders.UrlEncoder.Default.UrlEncode.

But I did not find UrlDecode. Is there one?

like image 600
bezejmeny Avatar asked Sep 07 '15 08:09

bezejmeny


People also ask

What does Httputility UrlEncode do?

HttpServerUtility. UrlEncode Method (System. Web) Encodes a string for reliable HTTP transmission from the Web server to a client through the URL.

What is Httputility in asp net?

This is a useful class. It provides methods (HtmlEncode and HtmlDecode) that manipulate HTML strings. Other methods support URL encoding. HtmlEncode, HtmlDecode.


1 Answers

System.Runtime.Extensions defines both UrlDecode and HtmlDecode.

namespace System.Net {     public static partial class WebUtility     {         public static string HtmlDecode(string value) { return default(string); }         public static string HtmlEncode(string value) { return default(string); }         public static string UrlDecode(string encodedValue) { return default(string); }         public static byte[] UrlDecodeToBytes(byte[] encodedValue, int offset, int count) { return default(byte[]); }         public static string UrlEncode(string value) { return default(string); }         public static byte[] UrlEncodeToBytes(byte[] value, int offset, int count) { return default(byte[]); }     } } 

Update

While System.Runtime.Extensions defines the extension, as you can notice from it's code the actual class you need to call is System.Net.WebUtility

Option 1: System.Net.WebUtility

  • Documentation
  • Source Code

Currently there are no publicly made plans to include Decode in Microsoft.Framework.WebEncoders.

Usage

System.Net.WebUtility.UrlEncode(myString) System.Net.WebUtility.UrlDecode(myString) 

Option 2: System.Text.Encodings.Web.UrlEncoder

  • Source Code

This is registered in the asp.net core service container and is injectable into your controllers etc.

like image 128
Mihai Dinculescu Avatar answered Sep 18 '22 16:09

Mihai Dinculescu