存储到数据库中是的html的特殊符号:<>等是就这样直接存储到数据库中,还是以编码的形式储存 当读取以后是否还需要转换什么的 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 直接存入,读取时,如果没有危险标记,比如<script>window.location='http://www.xxx.com'</script>,可直接输出,如果有这类危险标记(或是会影响页面布局的不完整html标记),可考虑用正则表达式替换去掉,最好的做法,是在存入前,就把不需要的标签先去掉,仅把安全的html标签按原样存入即可 楼上的说可考虑用正则表达式替换去掉,你所说的正规表达式是什么?用什么语言写啦?是javascrip还是C#等其他什么啦?能不能说的清楚一点 一般从表单里提交到数据库的内容肯定要先过滤的。比如<script><iframe><framset><a href="">这些标签把他们替换了就可以了。像<html>标签也要过滤,一般留言什么的显示出来后你肯定不想执行成网页的布局吧,肯定是显示成字符串形式。代码如下: //过滤所有script标记 public string wipeScript(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(@" on[\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); 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 return html; } 用户 'sa' 登录失败。该用户与可信 SQL Server 连接无关联。 怎样写 alipay 接口 textBox 隐藏后 js赋值问题 div定位的问题 高分求加为好友的界面及代码 送分题!开始学习asp.net 2.0 ,从教材的示例上,遇到2个小问题。 发我个ajaxpro的简单实例 问题:无法打开宏储存 有一个js脚本,为什么我传值总有错误 !急问关于XML问题,在线等待,100奉送 只有一个页面,要用什么绑定.在同一个地方显示,会显示几个logo 请问:怎样在GridView中最简单有效的实现添加记录的功能?
代码如下: //过滤所有script标记
public string wipeScript(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(@" on[\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);
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
return html;
}