Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which HttpUtility decode method to use?

Tags:

c#

asp.net

this may be a silly question, but it trips me up every time.

HttpUtility has the methods HtmlDecode and UrlDecode. Do these two methods decode anything (Html/Http related) I might find? When do I have to use them, and which one am I supposed to use?

Just now I hit an error. This is my error log:

Payment receiver was not [email protected]. (it was payment%40mysite.com).

But, I wrapped the email address here in HttpUtility.HtmlDecode before using it. It turns out I have to use .UrlDecode instead, but this email address didn't come from a URL so this wasn't obvious to me.

Can someone clarify this?

like image 517
Oliver Avatar asked Feb 24 '26 14:02

Oliver


1 Answers

See What is meant by htmlencode and urlencode?

It's the reverse of your case, but essentially you need to use UrlEncode/Decode anytime you are using an address of sorts (urls and yes, email addresses). HtmlEncode/Decode is for code that typically a browser would render (html/xml tags).

like image 146
PinnyM Avatar answered Feb 26 '26 05:02

PinnyM