1

Where is the Silverlight version of UrlEncode? I can't seem to find HttpUtility or anything like it.

Jonathan Allen
  • 68,373
  • 70
  • 259
  • 447

2 Answers2

4

1) HttpUtility is supported on Silverlight 3+. It's in the System.Windows.Browser though and not in the missing System.Web namespace. However it is not currently supported in WP7.

2) One undesirable option for Url Encoding that was previously mentioned would be to use Uri.EscapeUriString. Note that Uri.EscapeUriString has a different result then HttpUtility.UrlEncode for some special characters such as spaces and the '+' sign. So they're not functionally equivalent. Since some browsers or webservers can be sensitive to those changes I'd mildly suggest avoid using Uri.EscapeUriString for any non-propitiatory use (when you don't own both ends of the client<->server conversation).

Using Uri.EscapeUriString also increases the risk of accidentally using Uri.UnescapeDataString which is the mother of all atrocities. For more details on why that is and additional differences between HttpUtility and the Uri helper methods see this 2006 article from the ASP.Net team: Don't use .NET System.Uri.UnescapeDataString in URL Decoding

3) My suggested solution and the one I've been using with success in my WP7 apps is to copy the HttpUtility from Mono. That's based on Josh's suggestion from 2 years ago and has served me well in coding top WP7 apps.

Community
  • 1
  • 1
JustinAngel
  • 16,082
  • 3
  • 44
  • 73
2

use Uri.EscapeUriString instead

here is the MSDN documentation

Muad'Dib
  • 28,542
  • 5
  • 55
  • 68