Reputation: 689
this maybe sounds like an especially stupid question but in my asp.net-project I use HttpUtility.HtmlDecode
to decode following string:
string bar = HttpUtility.HtmlDecode("%3CFoobar%3E");
But the resulting string is the same exact one as before. What am I doing wrong?
Upvotes: 1
Views: 1822
Reputation: 22679
The HttpUtility class supports two types of encoding/decoding:
You have tried to decode an URL encoded string with HTML decoder.
Either use HTML encoding/decoding
const string original = "<Foobar>";
string encoded = HttpUtility.HtmlEncode(original); //<Foobar>
string decoded = HttpUtility.HtmlDecode(encoded); //<Foobar>
OR use URL encoding/decoding
const string original = "<Foobar>";
string encoded = HttpUtility.UrlEncode(original); //%3CFoobar%3E
string decoded = HttpUtility.UrlDecode(encoded); //<Foobar>
Upvotes: 5