Convert Special characters into Html Encoded characters

前端 未结 3 579
谎友^
谎友^ 2021-01-06 01:11

I want to converter all special characters into Html encoded characters. I found many post related to used HttpUtility.HtmlEncode(); , but it\'s only convert so

相关标签:
3条回答
  • 2021-01-06 01:30

    you can also do as follows without AntiXSS

    public static string HtmlEncode (string text)
    {
        string result;
        using (StringWriter sw = new StringWriter())
        {
            var x = new HtmlTextWriter(sw);
            x.WriteEncodedText(text);
            result = sw.ToString();
        }
        return result;
    
    }
    
    0 讨论(0)
  • 2021-01-06 01:37

    Yes.Using javascript Escape them.

    document.write(escape("3423424242<><><$$"));
    
    0 讨论(0)
  • 2021-01-06 01:46

    The Microsoft AntiXss Library can accomplish this;

    string p = Microsoft.Security.Application.Encoder.HtmlEncode("aaa <b>sdf</b> š,Ø,þ,›,Ù", true);
    Response.Write(p);
    

    For

    aaa &lt;b&gt;sdf&lt;/b&gt; &scaron;,&Oslash;,&thorn;,&rsaquo;,&Ugrave;
    
    0 讨论(0)
提交回复
热议问题