Reputation: 53378
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!
Upvotes: 7
Views: 10278
Reputation: 2721
You should really look into using the AntiXSS
library of the WPL.
You don't need System.Web!
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
Upvotes: 2
Reputation: 120917
You can use the HttpUtility
class from System.Web.
Upvotes: 2
Reputation: 643
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.
Upvotes: 11
Reputation: 41981
I believe System.Net.WebUtility.HtmlEncode
will provide this functionality. MSDN reference for WebUtility.HTMLEncode
Upvotes: 21