
asp.net如何将数据库的html代码调用出来时进行显示
我用Asp.Net开发新闻网站的时候,首先在FCKEditor在线编辑器上操作,把图片上传放在服务器上,用一个数据库来保存新闻,新闻内容是图文混排的!保存的都是代码,然后...
我用Asp.Net开发新闻网站的时候,首先在FCKEditor在线编辑器上操作,把图片上传放在服务器上,用一个数据库来保存新闻,新闻内容是图文混排的!保存的都是代码,然后用DetailsView或GridView控件进行显示时 要怎么样才能把HTML代码去掉显示成原来排版时的图文混排呢? 谢谢....
展开
2个回答
展开全部
public static string Nohtml(string Htmlstr, int leng)
{
string Htmlstring = string.Empty;
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
//删除HTML
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"-->", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"<!--.*", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"(\d+);", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, "xp_cmdshell", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, ">", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, "<", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, "<p>", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, "</p>", "", RegexOptions.IgnoreCase);
////删除与数据库相关的词
//Htmlstring = Regex.Replace(Htmlstring, "select", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "insert", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "delete from", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "count''", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "drop table", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "truncate", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "asc", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "mid", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "char", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "xp_cmdshell", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "exec master", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "net localgroup administrators", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "and", "", RegexOptions.IgnoreCase);
Htmlstring = SubString(Htmlstr, leng);
return Htmlstring;
}
输出的时候先处理一下。 但是不要改动数据库不然变不回去了。
{
string Htmlstring = string.Empty;
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
//删除HTML
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"-->", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"<!--.*", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, @"(\d+);", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, "xp_cmdshell", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, ">", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, "<", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, "<p>", "", RegexOptions.IgnoreCase);
Htmlstr = System.Text.RegularExpressions.Regex.Replace(Htmlstr, "</p>", "", RegexOptions.IgnoreCase);
////删除与数据库相关的词
//Htmlstring = Regex.Replace(Htmlstring, "select", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "insert", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "delete from", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "count''", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "drop table", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "truncate", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "asc", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "mid", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "char", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "xp_cmdshell", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "exec master", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "net localgroup administrators", "", RegexOptions.IgnoreCase);
//Htmlstring = Regex.Replace(Htmlstring, "and", "", RegexOptions.IgnoreCase);
Htmlstring = SubString(Htmlstr, leng);
return Htmlstring;
}
输出的时候先处理一下。 但是不要改动数据库不然变不回去了。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询