[转载]C# 中对html 标签过滤
private string FilterHTML(string html)
{
System.Text.RegularExpressions.Regex regex1 =
new System.Text.RegularExpressions.Regex(@"<script[sS]+</script *>",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex2 =
new System.Text.RegularExpressions.Regex(@" href *= *[sS]*script *:",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex3 =
new System.Text.RegularExpressions.Regex(@" no[sS]*=",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex4 =
new System.Text.RegularExpressions.Regex(@"<iframe[sS]+</iframe *>",
System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex5 =
new System.Text.RegularExpressions.Regex(@"<frameset[sS]+</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>", "");
html = Regex.Replace(html, "[\f\n\r\t\v]", ""); //过滤回车换行制表符
return html;
}
[转载]C# 中对html 标签过滤的更多相关文章
- 转载-struts中logic标签使用
Struts中Logic逻辑标签的作用及用法 Struts中Logic逻辑标签的作用及用法 2006年10月18日 星期三 21:34 Terry原创,转载请说明作者及出处 Logic标签大部分的功能 ...
- 过滤字符串中的html标签
C#中,我们有时需要过滤掉字符串中的部分html标签,以下是一些简单的html标签过滤方法,使用的主要方式是正则表达式 public static string ClearHtml(string ht ...
- [转]Filter实现处理中文乱码,转义html标签,过滤敏感词
原文地址:http://www.cnblogs.com/xdp-gacl/p/3952405.html 在filter中可以得到代表用户请求和响应的request.response对象,因此在编程中可 ...
- 在jsp页面中使用自定义标签
在某些场景中,自定义标签可封装大量代码,使页面变得更简洁,标签也可以很方便地在不同页面中实现通用而不必去粘贴大量的js代码.现在把最近做的一个自定义标签在这里总结一下.首先总结一下关于自定义标签的一些 ...
- 【转载】C#防SQL注入过滤危险字符信息
不过是java开发还是C#开发或者PHP的开发中,都需要关注SQL注入攻击的安全性问题,为了保证客户端提交过来的数据不会产生SQL注入的风险,我们需要对接收的数据进行危险字符过滤来防范SQL注入攻击的 ...
- 17、SAM文件格式说明(转载迷宫中的将军)
1. SAM格式说明 SAM代表Sequence Alignment/Map格式,是一种制表符分隔的文本格式,包含一个可选的头部分(header section,有人称之为“注释部分”),和一个比对部 ...
- Tomcat之web.xml中的<url-pattern>标签
关于web.xml配置中的<url-pattern> 标签<url-pattern> <url-pattern>是我们用Servlet做Web项目时需要经常配置的标 ...
- PHP替换HTML文件中所有a标签的HREF属性,其他不变
转载出处:http://www.luanxin.top/index.php/archives/21/ 仿站的时候扒下来的代码a链接总是指向别的地方,要一个一个改的话都要累死了,展示的时候随便点一下就乱 ...
- struts2中的s标签
那就从简单的标签说起吧!1.x中常用的标签只有4中html.bean.logic.tiles 而struts2.0里的标签却没有分类,只用在jsp头文件加上 <%@ taglib prefix= ...
随机推荐
- 基于ARM的RealView MDK开发环境
RealView MDK可以对各种嵌入式处理器的软件开发工具.这么高端,着实很吸引我,ADS12还不知道怎么搞,居然还有这么高端的,但是还是得了解一下唉.洗这个自动配 置启动代码,集成Flash烧写模 ...
- 使用kdbg或nemiver调试ROS
Kdbg Kdbg是KDE环境下的一个gdb的前端GUI,使用起来比较友好,速度也很快,安装和使用请参考: http://www.kdbg.org/ 在UBUNTU下可以直接使用APT安装: sudo ...
- Apple Watch: WatchKit 应用程序要点
Apple Watch: WatchKit 应用程序要点 本文译自:Apple Watch: WatchKit App Essentials WatchKit 应用程序架构 上一篇文章简单介绍了 Wa ...
- 【转】ASP.NET MVC 使用 FluentScheduler 定时器计划任务
MacBook Pro 只有四个 USB Type-C 接口是否错了? 一项新技术的诞生总会对已存在的事物造成冲击或影响,如果大家都害怕冲击与影响,那这个世界永远像现在不变就行了,大家都好好的,待在自 ...
- Java_Web学习路线
- HTML——<meta http-equiv="content-type" content="text/html; charset=UTF-8">
没有添加这句话的编码方式的话,很容易就乱码了 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&g ...
- jquery实现asp.net 网页鼠标所在位置
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="mouseposition. ...
- 3D Touch ? 木有6s,也阔以玩!!!
3D Touch 之 Peek & Pop 3D Touch 是iOS9之后专为 iPhone6s 机型加入的新特性,这一新技术移植于 Mac Book 上的 ForceTouch 更准确地说 ...
- Objective-C 【继承、变量修饰符(私有变量/方法)、description方法】
------------------------------------------- 继承 一段代码: #import <Foundation/Foundation.h> @interf ...
- JavaScript解析json
后台数据经常以json数据格式传回前台,解析当然首选JSON对象. JSON对象有两个方法,使用JSON.parse(str)可以将json字符串解析成js中的对象. var o = JSON.par ...