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)));
&
s. You are assigning it to the Text property. It should take care of the HTML encoding internally. The only thing you need to worry about is it being a valid URI. – Rejuvenate