一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

ASP.NET過濾HTML字符串方法總結

本文實例講述了ASP.NET過濾HTML字符串的方法,供大家參考使用,具體代碼如下:

///  <summary>去除HTML標記 ///     ///  </summary>   ///  <param name="Htmlstring">包括HTML的源碼</param>   ///  <returns>已經去除后的文字</returns>   public static string GetNoHTMLString(string Htmlstring) {   //刪除腳本     Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);   //刪除HTML     Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);   Htmlstring = Regex.Replace(Htmlstring, @"([/r/n])[/s]+", "", RegexOptions.IgnoreCase);   Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);   Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);   Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "/"", RegexOptions.IgnoreCase);   Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);   Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);   Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);   Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", "  ", RegexOptions.IgnoreCase);   Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "/xa1", RegexOptions.IgnoreCase);   Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "/xa2", RegexOptions.IgnoreCase);   Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "/xa3", RegexOptions.IgnoreCase);   Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "/xa9", RegexOptions.IgnoreCase);   Htmlstring = Regex.Replace(Htmlstring, @"&#(/d+);", "", RegexOptions.IgnoreCase);   Htmlstring.Replace("<", "");   Htmlstring.Replace(">", "");   Htmlstring.Replace("/r/n", "");   Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();   return Htmlstring; } /// <summary>獲取顯示的字符串,可顯示HTML標簽,但把危險的HTML標簽過濾,如iframe,script等。 ///  /// </summary> /// <param name="str">未處理的字符串</param> /// <returns></returns> public static string GetSafeHTMLString(string str) {   str = Regex.Replace(str, @"<applet[^>]*?>.*?</applet>", "", RegexOptions.IgnoreCase);   str = Regex.Replace(str, @"<body[^>]*?>.*?</body>", "", RegexOptions.IgnoreCase);   str = Regex.Replace(str, @"<embed[^>]*?>.*?</embed>", "", RegexOptions.IgnoreCase);   str = Regex.Replace(str, @"<frame[^>]*?>.*?</frame>", "", RegexOptions.IgnoreCase);   str = Regex.Replace(str, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);   str = Regex.Replace(str, @"<frameset[^>]*?>.*?</frameset>", "", RegexOptions.IgnoreCase);   str = Regex.Replace(str, @"<html[^>]*?>.*?</html>", "", RegexOptions.IgnoreCase);   str = Regex.Replace(str, @"<iframe[^>]*?>.*?</iframe>", "", RegexOptions.IgnoreCase);   str = Regex.Replace(str, @"<style[^>]*?>.*?</style>", "", RegexOptions.IgnoreCase);   str = Regex.Replace(str, @"<layer[^>]*?>.*?</layer>", "", RegexOptions.IgnoreCase);   str = Regex.Replace(str, @"<link[^>]*?>.*?</link>", "", RegexOptions.IgnoreCase);   str = Regex.Replace(str, @"<ilayer[^>]*?>.*?</ilayer>", "", RegexOptions.IgnoreCase);   str = Regex.Replace(str, @"<meta[^>]*?>.*?</meta>", "", RegexOptions.IgnoreCase);   str = Regex.Replace(str, @"<object[^>]*?>.*?</object>", "", RegexOptions.IgnoreCase);   return str; } 

AspNet技術ASP.NET過濾HTML字符串方法總結,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 色婷婷视频 | 成年美女黄网站色大免费视频 | 国产一区二区三区高清 | 亚洲天堂久久 | 怡红院亚洲红怡院在线观看 | 成人嗯啊视频在线观看 | 免看一级a毛片一片成人不卡 | 色欧美色| 狠狠色成人综合首页 | 91播放在线 | 亚洲国产激情一区二区三区 | 日本一区二区三区中文字幕 | 麻豆91制片厂 | 国内福利视频 | 五月婷婷免费视频 | 免费黄色在线 | 欧美美女视频网站 | 免费精品国产福利片 | 成人福利在线观看 | 国内第一永久免费福利视频 | 国产麻豆精品一区 | 国产精品12页 | 女性毛片| 国产成人 免费观看 | 国产在视频线精品视频www666 | 自拍偷拍国语对白 | 色多多福利网站 | 美女视频网站黄色 | 麻豆精品密在线观看 | 在线观看日本亚洲一区 | 91麻豆久久 | 19国产精品麻豆免费观看 | 久久久久久极精品久久久 | 丝袜综合网 | 玖玖爱精品视频 | 激情欧美一区二区三区 | 夜夜操天天干 | 在线看的黄色网址 | 91视频站 | 蕾丝视频成人★在线观看 | 38pao强力打造永久免费高清视频 |