C# method to do URL encoding?

56,525

Solution 1

HttpUtility.UrlEncode

Solution 2

System.Net.WebUtility.UrlEncode(str)

Solution 3

HttpServerUtility.UrlEncode might be exactly what you are looking for.

Solution 4

Use Server.UrlEncode

You need an instance of the HttpServerUtility class, because the UrlEncode method is not static.

See http://msdn.microsoft.com/en-us/library/system.web.httpserverutility(v=VS.90).aspx

Share:
56,525
Greg
Author by

Greg

Updated on July 10, 2022

Comments

  • Greg
    Greg almost 2 years

    what c# class method can I use to URL encode a URL string?

    In my use case I want to pass a URL string as a URL parameter itself. So like burying a URL within a URL. Without some encoding the "&" and "?" characters in the inner URL can get picked up when the parameters for the outer Url parameters are processed

    thanks