I am generating some HTML and I want to generate an XSS- and database-content-safe mailto
link. What is the proper encoding to use here? How's this?
myLiteral.Text = string.Format(
"mailto:{0}?Content-Type=text/html&Subject={1}&body={2}",
HttpUtility.UrlEncode(email_address),
HttpUtility.UrlEncode(subject),
HttpUtility.UrlEncode(body_message));
Should I use UrlEncode
here? HtmlEncode
? Do what I did, then HtmlEncode
the entirety? I'm writing HTML of a URL, so I'm a little unclear...
@Quentin, is this what you're describing? (Changed &
s to &
since I'm about to HtmlEncode
...)
myLiteral.Text =
HttpUtility.HtmlEncode(HttpUtility.UrlEncode(
string.Format(
"mailto:{0}?Content-Type=text/html&Subject={1}&body={2}",
email_address, subject, body_message)));
You are putting some content in a URL, then representing that URL in HTML. So URLEncode it then HTMLEncode what you get from URLEncode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With