首页  ·  知识 ·  云计算
asp.net过滤所有html标识函数
网友  其它|  综合  编辑:德仔   图片来源:网络
//添加文章过滤 public string checkStr(string html)
//添加文章过滤
    public string checkStr(string html)
    {
        System.Text.RegularExpressions.Regex regex1 =
            new System.Text.RegularExpressions.Regex(@"<script[\s\S]+</script *>",
                System.Text.RegularExpressions.RegexOptions.IgnoreCase);
        System.Text.RegularExpressions.Regex regex2 =
            new System.Text.RegularExpressions.Regex(@" href *= *[\s\S]*script *:",
                System.Text.RegularExpressions.RegexOptions.IgnoreCase);
        System.Text.RegularExpressions.Regex regex3 =
            new System.Text.RegularExpressions.Regex(@" no[\s\S]*=",
                System.Text.RegularExpressions.RegexOptions.IgnoreCase);
        System.Text.RegularExpressions.Regex regex4 =
            new System.Text.RegularExpressions.Regex(@"<iframe[\s\S]+</iframe *>",
                System.Text.RegularExpressions.RegexOptions.IgnoreCase);
        System.Text.RegularExpressions.Regex regex5 =
            new System.Text.RegularExpressions.Regex(@"<frameset[\s\S]+</frameset *>",
                System.Text.RegularExpressions.RegexOptions.IgnoreCase);
        System.Text.RegularExpressions.Regex regex6 =
                    new System.Text.RegularExpressions.Regex(@"\<img[^\>]+\>",
                        System.Text.RegularExpressions.RegexOptions.IgnoreCase);
        System.Text.RegularExpressions.Regex regex7 =
            new System.Text.RegularExpressions.Regex(@"</p>",
                System.Text.RegularExpressions.RegexOptions.IgnoreCase);
        System.Text.RegularExpressions.Regex regex8 =
            new System.Text.RegularExpressions.Regex(@"<p>",
                System.Text.RegularExpressions.RegexOptions.IgnoreCase);
        System.Text.RegularExpressions.Regex regex9 =
            new System.Text.RegularExpressions.Regex(@"<[^>]*>",
                System.Text.RegularExpressions.RegexOptions.IgnoreCase);
        html = regex1.Replace(html, ""); //过滤<script></script>标记
        html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性
        html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
        html = regex4.Replace(html, ""); //过滤iframe
        html = regex5.Replace(html, ""); //过滤frameset
        html = regex6.Replace(html, ""); //过滤frameset
        html = regex7.Replace(html, ""); //过滤frameset
        html = regex8.Replace(html, ""); //过滤frameset
        html = regex9.Replace(html, "");
        html = html.Replace(" ", "");
        html = html.Replace("</strong>", "");
        html = html.Replace("<strong>", "");
        return html;
    }
文章来自学IT网:http://www.xueit.com/html/2008-11/117_4433_00.html
本文作者:网友 来源:其它|
CIO之家 www.ciozj.com 微信公众号:imciow
   
免责声明:本站转载此文章旨在分享信息,不代表对其内容的完全认同。文章来源已尽可能注明,若涉及版权问题,请及时与我们联系,我们将积极配合处理。同时,我们无法对文章内容的真实性、准确性及完整性进行完全保证,对于因文章内容而产生的任何后果,本账号不承担法律责任。转载仅出于传播目的,读者应自行对内容进行核实与判断。请谨慎参考文章信息,一切责任由读者自行承担。
延伸阅读