1. private string FilterHTML(string html)
  2. {
  3. System.Text.RegularExpressions.Regex regex1 =
  4. new System.Text.RegularExpressions.Regex(@"<script[sS]+</script *>",
  5. System.Text.RegularExpressions.RegexOptions.IgnoreCase);
  6. System.Text.RegularExpressions.Regex regex2 =
  7. new System.Text.RegularExpressions.Regex(@" href *= *[sS]*script *:",
  8. System.Text.RegularExpressions.RegexOptions.IgnoreCase);
  9. System.Text.RegularExpressions.Regex regex3 =
  10. new System.Text.RegularExpressions.Regex(@" no[sS]*=",
  11. System.Text.RegularExpressions.RegexOptions.IgnoreCase);
  12. System.Text.RegularExpressions.Regex regex4 =
  13. new System.Text.RegularExpressions.Regex(@"<iframe[sS]+</iframe *>",
  14. System.Text.RegularExpressions.RegexOptions.IgnoreCase);
  15. System.Text.RegularExpressions.Regex regex5 =
  16. new System.Text.RegularExpressions.Regex(@"<frameset[sS]+</frameset *>",
  17. System.Text.RegularExpressions.RegexOptions.IgnoreCase);
  18. System.Text.RegularExpressions.Regex regex6 =
  19. new System.Text.RegularExpressions.Regex(@"<img[^>]+>",
  20. System.Text.RegularExpressions.RegexOptions.IgnoreCase);
  21. System.Text.RegularExpressions.Regex regex7 =
  22. new System.Text.RegularExpressions.Regex(@"</p>",
  23. System.Text.RegularExpressions.RegexOptions.IgnoreCase);
  24. System.Text.RegularExpressions.Regex regex8 =
  25. new System.Text.RegularExpressions.Regex(@"<p>",
  26. System.Text.RegularExpressions.RegexOptions.IgnoreCase);
  27. System.Text.RegularExpressions.Regex regex9 =
  28. new System.Text.RegularExpressions.Regex(@"<[^>]*>",
  29. System.Text.RegularExpressions.RegexOptions.IgnoreCase);
  30. html = regex1.Replace(html, ""); //过滤<script></script>标记
  31. html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性
  32. html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
  33. html = regex4.Replace(html, ""); //过滤iframe
  34. html = regex5.Replace(html, ""); //过滤frameset
  35. html = regex6.Replace(html, ""); //过滤frameset
  36. html = regex7.Replace(html, ""); //过滤frameset
  37. html = regex8.Replace(html, ""); //过滤frameset
  38. html = regex9.Replace(html, "");
  39. //html = html.Replace(" ", "");
  40. html = html.Replace("</strong>", "");
  41. html = html.Replace("<strong>", "");
  42. html = Regex.Replace(html, "[\f\n\r\t\v]", ""); //过滤回车换行制表符
  43. return html;
  44. }

[转载]C# 中对html 标签过滤的更多相关文章

  1. 转载-struts中logic标签使用

    Struts中Logic逻辑标签的作用及用法 Struts中Logic逻辑标签的作用及用法 2006年10月18日 星期三 21:34 Terry原创,转载请说明作者及出处 Logic标签大部分的功能 ...

  2. 过滤字符串中的html标签

    C#中,我们有时需要过滤掉字符串中的部分html标签,以下是一些简单的html标签过滤方法,使用的主要方式是正则表达式 public static string ClearHtml(string ht ...

  3. [转]Filter实现处理中文乱码,转义html标签,过滤敏感词

    原文地址:http://www.cnblogs.com/xdp-gacl/p/3952405.html 在filter中可以得到代表用户请求和响应的request.response对象,因此在编程中可 ...

  4. 在jsp页面中使用自定义标签

    在某些场景中,自定义标签可封装大量代码,使页面变得更简洁,标签也可以很方便地在不同页面中实现通用而不必去粘贴大量的js代码.现在把最近做的一个自定义标签在这里总结一下.首先总结一下关于自定义标签的一些 ...

  5. 【转载】C#防SQL注入过滤危险字符信息

    不过是java开发还是C#开发或者PHP的开发中,都需要关注SQL注入攻击的安全性问题,为了保证客户端提交过来的数据不会产生SQL注入的风险,我们需要对接收的数据进行危险字符过滤来防范SQL注入攻击的 ...

  6. 17、SAM文件格式说明(转载迷宫中的将军)

    1. SAM格式说明 SAM代表Sequence Alignment/Map格式,是一种制表符分隔的文本格式,包含一个可选的头部分(header section,有人称之为“注释部分”),和一个比对部 ...

  7. Tomcat之web.xml中的<url-pattern>标签

    关于web.xml配置中的<url-pattern> 标签<url-pattern> <url-pattern>是我们用Servlet做Web项目时需要经常配置的标 ...

  8. PHP替换HTML文件中所有a标签的HREF属性,其他不变

    转载出处:http://www.luanxin.top/index.php/archives/21/ 仿站的时候扒下来的代码a链接总是指向别的地方,要一个一个改的话都要累死了,展示的时候随便点一下就乱 ...

  9. struts2中的s标签

    那就从简单的标签说起吧!1.x中常用的标签只有4中html.bean.logic.tiles 而struts2.0里的标签却没有分类,只用在jsp头文件加上 <%@ taglib prefix= ...

随机推荐

  1. [转].net 调用oracle存储过程返回多个记录集

    本文转自:http://www.netwinform.com/articleinfo.aspx?id=17 存储过程: CREATE OR REPLACE PROCEDURE p_query_cs ( ...

  2. [CSS][转载]内层div的margin-top影响外层div

    参考 内层div的margin-top影响外层div——引出外边距合并 div嵌套导致子区域margin-top失效不起作用的解决方法 我使用的是在外层的div中添加 border: 1px soli ...

  3. ArryList vs LinkedList

    references: http://www.javaperformancetuning.com/articles/randomaccess.shtml http://stackoverflow.co ...

  4. 【JAVA】final修饰Field

    一.简介 final修饰符可以用来修饰变量.方法.类.final修饰变量时一旦被赋值就不可以改变. 二.final成员变量 成员变量是随类初始化或对象初始化而初始化的.当类初始化的时候,会给类变量分配 ...

  5. ###g++编译器

    点击查看Evernote原文. #@author: gr #@date: 2014-07-20 #@email: forgerui@gmail.com 对g++编译器不是特别熟悉,希望借此熟悉一下. ...

  6. unity访问php

    长连接,弱联网.不好意思,这俩不是一个意思. 反过来说,短连接,强联网,是不是有点别扭呢. 你可以不会php,甚至你可以不知道php是干什么的. 百度php安装环境,自行搭建好环境,顺便测试一下.(下 ...

  7. C#定义自定义类型转换

    类型转换不限于单一继承链中的类型(派生类转换为基类或者基类转换为派生类),完全不相关的类型之间也能进行转换.关键在于在两个类型之间提供转型操作符. 在下面这样的情况下应该定义显式转型操作符: 在转型有 ...

  8. C++异常处理(Exception Handling)

    在C++中引入了三种操作符来处理程序的出错情况,分别是:try  , throw  ,  catch 1.基本的用法如下: try{ //code to be tried throw exceptio ...

  9. 解决rtl8723be无线网卡驱动频繁断网问题

    买了新本子,用的是rtl8723be无线网卡,连WIFI时总是断网.Windows下好解决,Ubuntu下可就麻烦了,又是升级内核又是编译驱动的,折腾了一天,终于找到了解决办法: # echo &qu ...

  10. JavaScript 继承的几种模式

    /** * Created by 2016 on 2016/6/5. */ //1.原型链继承 //把子类的原型,定义为超类的实例 通过原型来访问超类的方法和属性 function Person(){ ...