.NET类库中的Html编码

发布于 2024-10-03 12:30:35 字数 265 浏览 0 评论 0原文

我有一个用于发送电子邮件的实用程序类。电子邮件生成为 html。

我在编码无法正确显示的特殊字符时遇到问题。

但是,我无法弄清楚如何使用 HtmlEncode,因为我没有当前的 HttpContext。是否有一个 .Net 类可以将特殊字符转换为 html 代码,而无需在 Asp.Net 下运行?

我希望这是有道理的,我对所有这些东西的工作原理有点不稳定。谢谢!

I have a utility class for sending emails. The emails are generated as html.

I'm having problems with encoding special characters which aren't getting displayed correctly.

However, I can't work out how to use HtmlEncode as I don't have a current HttpContext. Is there a .Net class which will translate special characters to html codes without running under Asp.Net?

I hope that makes sense, I'm a bit flaky about how all this stuff works. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

风尘浪孓 2024-10-10 12:30:35

我相信 System.Net.WebUtility.HtmlEncode 将提供此功能。 WebUtility.HTMLEncode 的 MSDN 参考

I believe System.Net.WebUtility.HtmlEncode will provide this functionality. MSDN reference for WebUtility.HTMLEncode

香草可樂 2024-10-10 12:30:35

您可以导入 System.Web 命名空间并使用 HttpUtility 类。尽管它是一个 Web 程序集,但我认为没有必要在 Web 环境下运行它才能工作。

You can import the System.Web namespace and use the HttpUtility class. Altohugh it's a Web assembly I don't think it's neccesary to be running under a Web environment for it to work.

智商已欠费 2024-10-10 12:30:35

您可以使用 HttpUtility 来自 System.Web 的类。

You can use the HttpUtility class from System.Web.

太傻旳人生 2024-10-10 12:30:35

您确实应该考虑使用 WPLAntiXSS 库。

  1. 不需要System.Web!

  2. 它使用白名单包含原则(System.Web 编码使用黑名单)。只有已知安全的字符才会被信任,所有其他字符都会被正确编码

You should really look into using the AntiXSS library of the WPL.

  1. You don't need System.Web!

  2. It uses a white-list inclusion principle (System.Web encoding uses black-listing). Only characters that are known to be safe will be trusted and all others will be properly encoded

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文