2

I got an old Program(class library) developed by .Net 2. Recently I want to use that Program in new project which is use .Net4(For new WPF feature's ). so there is a big problem:

.Net4 don't support System.Web and as result it can't be use Httputility.urldecode!!

So what is urldecode jop? and how can I change that to something, which is support by .Net4?

Nadeem_MK
  • 7,533
  • 7
  • 50
  • 61
Rev
  • 2,269
  • 8
  • 45
  • 75

5 Answers5

10

HttpUtility is wild goose chase for c# users since it's not already there (referenced)
2 alternatives :

  string a =  System.Uri.EscapeUriString("https://some.url.goes.here"); // for path
  string b = System.Uri.EscapeDataString("parameter1=1&parameter2=something"); // for params
Elazaron
  • 476
  • 11
  • 21
  • 1
    this should be the accepted answer, adding System.Web just for the sake of escaping and unescaping an string is just not the way to go. – Didier Caron Sep 23 '14 at 09:46
  • Escape***String methods are a replacement for UrlEncode. For UrlDecode you need Uri,UnescapeDataString – gxclarke Aug 02 '17 at 14:22
3

Try the UrlDecode method on HttpServerUtility:

System.Web.HttpContext.Current.Server.UrlDecode()
gerrod
  • 6,119
  • 6
  • 33
  • 45
2

You can also use System.Net.WebUtility.UrlDecode

Usman Rauf
  • 90
  • 1
  • 3
  • 8
2

If you really have to run against the client profile (which doesnt include HttpUtility) then you could check this Alternative to HttpUtility for .NET 3.5 SP1 client framework?. (That question is about 3.5 sp1 but nothing has changed in this regard in 4.0)

You really should see if you can't just use the full framework though.

Community
  • 1
  • 1
alun
  • 3,393
  • 21
  • 26
1

As you can see in below link, .NET Framework 4 is supporting the HttpUtility. As @Alun is mentioend above, I think you use .NET 4 Client Profile

HttpUtility Class

Peyman
  • 3,068
  • 1
  • 18
  • 32