最佳答案
HTTPUtility.HTMLEncode()
method, detailed here:
public static void HtmlEncode(
string s,
TextWriter output
)
Usage:
String TestString = "This is a <Test String>.";
StringWriter writer = new StringWriter();
Server.HtmlEncode(TestString, writer);
String EncodedString = writer.ToString();