Using URL Encode with .net Core

Frustratingly .net Core early releases were without URL Encode and Decode methods. Whereas previously you were able to access the HTTPUtility namespace for encoding and decoding strings, this was not ported to .net core.

Until now!

Microsoft has moved the UrlEncode and Decode methods into a WebUtility static class. If you are super nosy you can see the code that’s doing your encoding here.

To get access you need to install this nuget package, which at the time of writing means running this command from your package command line :

Install-Package Microsoft.AspNet.WebUtilities -Pre

Now you have access to URL Encoding

var myEncodedString = System.Net.WebUtility.UrlEncode("my string");
Join over 3,000 subscribers who are receiving our weekly post digest, a roundup of this weeks blog posts.
We hate spam. Your email address will not be sold or shared with anyone else.

1 comment

  1. It’s been over a year since this article published, so I assume the way to accomplish this in .Net is completely different now.

Leave a Reply

Your email address will not be published.