According to MSDN (see "Allow restricted HTML input"), the best way to misinform the input HTML is to call HttpUtility.HtmlEncode () on your input and then selectively replace the encoding with all your whitelists as follows:
<%@ Page Language="C#" ValidateRequest="false"%> <script runat="server"> void submitBtn_Click(object sender, EventArgs e) { // Encode the string input StringBuilder sb = new StringBuilder( HttpUtility.HtmlEncode(htmlInputTxt.Text)); // Selectively allow and <i> sb.Replace("<b>", "<b>"); sb.Replace("</b>", ""); sb.Replace("<i>", "<i>"); sb.Replace("</i>", ""); Response.Write(sb.ToString()); } </script>
See also in this article .
Repo man
source share