我在后台使用DotNetTextBox编辑器,然后使用(1)UBB代码(2)过滤所有script标记(3)Server.HtmlEncode html编码 等方法将内容插入到content字段里,我使用的是access数据库,插入后数据库里的 "<" 符号 都转换横 "<"字符了,而去flash和word都能插入到数据库,现在我修改或查询时我使用了还原方法
//还原
public string hy(string bl) {
return bl.Replace("<","<").Replace(">",">").Replace(""","\"").Replace(" "," ").Replace("&","&");
}但是这个字段的内容转换成"<"符号后在查询也里直接html代码格式显示,而不显示图片,这个问题怎么解决,请高手帮帮我,我可以给您高分(80)。
//还原
public string hy(string bl) {
return bl.Replace("<","<").Replace(">",">").Replace(""","\"").Replace(" "," ").Replace("&","&");
}但是这个字段的内容转换成"<"符号后在查询也里直接html代码格式显示,而不显示图片,这个问题怎么解决,请高手帮帮我,我可以给您高分(80)。
string ubbzh(string bl) {
Random sj = new Random();
bl=Regex.Replace(bl,"\\[URL\\](.*?)\\[/URL\\]","<a href=\"$1\" target=\"_blank\" title=\"$1\">$1</a>");
bl=Regex.Replace(bl,"\\[URL=(.*?)\\](.*?)\\[/URL\\]","<a href=\"$1\" target=\"_blank\" title=\"$1\">$2</a>");
bl=Regex.Replace(bl,"\\[MAIL\\](.*?)\\[/MAIL\\]","<a href=\"mailto:$1\">$1</a>");
bl=Regex.Replace(bl,"\\[MAIL=(.*?)\\](.*?)\\[/MAIL\\]","<a href=\"mailto:$1\">$2</a>");
bl=Regex.Replace(bl,"\\[COLOR\\](.*?)\\[/COLOR\\]","<span style=\"color:#"+sj.Next(000000,999999)+";\">$1</span>");
bl=Regex.Replace(bl,"\\[COLOR=(.*?)\\](.*?)\\[/COLOR\\]","<span style=\"color:$1\">$2</span>");
bl=Regex.Replace(bl,"\\[MOVE\\](.*?)\\[/MOVE\\]","<marquee>$1</marquee>");
bl=Regex.Replace(bl,"\\[STRONG\\](.*?)\\[/STRONG\\]","<strong>$1</strong>");
bl=Regex.Replace(bl,"\\[EM\\](.*?)\\[/EM\\]","<em>$1</em>");
return bl;
} //过滤所有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;
}
//编码
string html(string bl) {
return HttpContext.Current.Server.HtmlEncode(bl.Replace("'","''"));
}
这些时我使用的方法,请大家帮帮我啊,我现在在线.....
public static string UBBToHTML(string str)
{
str= str.Replace(" "," ");
str= str.Replace("<","<");
str= str.Replace(">",">");
str= str.Replace("\r\n","<BR>");
return str;
}
UBB参考