Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL Encode and Decode in ASP.NET Core

HttpContext.Current.Server.UrlEncode

This does only work in .NET Framework. How can I encode or decode URI arguments in ASP.NET Core?

like image 273
wtf512 Avatar asked Sep 29 '22 19:09

wtf512


1 Answers

  • For ASP.NET Core 2.0+ just add System.Net namespace - WebUtility class is shipped as part of System.Runtime.Extensions nuget package, that is referenced by default in ASP.NET Core project.

  • For the previous version add Microsoft.AspNetCore.WebUtilities nuget package.

Then the WebUtility class will be available for you:

public static class WebUtility
{
    public static string UrlDecode(string encodedValue);
    public static string UrlEncode(string value);
}
like image 280
Set Avatar answered Oct 13 '22 01:10

Set