我如何正确编码一个mailto链接? [英] How do I properly encode a mailto link?

查看:104
本文介绍了我如何正确编码一个mailto链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在生成一些HTML,我想生成一个XSS和数据库内容安全的 mailto 链接。什么是适当的编码在这里使用?这是怎么回事?

  myLiteral.Text = string.Format(
mailto:{0}?Content-Type = text / html& amp; amp; Subject = {1}& amp; body = {2},
HttpUtility.UrlEncode(email_address),
HttpUtility.UrlEncode(subject),
HttpUtility。以UrlEncode(body_message));

我应该在这里使用 UrlEncode 吗? 的HTMLEncode ?做我做的,然后 HtmlEncode 整体?我正在编写一个URL的HTML,所以我有点不清楚......

@Quentin,这是你描述的吗? (由于我即将& amp; s变为& > HtmlEncode ...)

  myLiteral.Text = 
HttpUtility.HtmlEncode(HttpUtility.UrlEncode
string.Format(
mailto:{0}?Content-Type = text / html& Subject = {1}& body = {2},
email_address,subject,body_message )));


解决方案

您正在将一些内容放入网址中, HTML中的该URL。所以URLEncode它然后HTMLEncode你从URLEncode得到什么。


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.

这篇关于我如何正确编码一个mailto链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆