天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

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字符串方法總結,轉載需保留來源!

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

主站蜘蛛池模板: 亚洲 自拍 偷拍 另类综合图区 | 7723日本高清完整版在线观看 | 甜性涩爱快播 | 久久久精品3d动漫一区二区三区 | 综合一区无套内射中文字幕 | 国产精品一区二区四区 | 久久re视频这里精品09首页 | 色妹子综合 | 亚洲色婷婷久久精品AV蜜桃久久 | 色婷婷综合久久久中文字幕 | 亚洲精品AV一二三区无码 | 最近中文字幕在线中文视频 | 亚洲国产精品无码中文在线 | 国内精品视频一区二区在线观看 | 国产呻吟久久久久久久92 | 久久毛片免费看一区二区三区 | 国产又色又爽又刺激在线播放 | 一本到道免费线观看 | 最新国产在线视频在线 | 91热久久免费频精品99欧美 | 一区二区三区内射美女毛片 | 久久re视频精品538在线 | 国产91网站在线观看免费 | 菠萝菠萝蜜高清观看在线 | 日本一区精品久久久久影院 | 超碰v | 吃奶啃奶玩乳漫画 | 日本久久精品毛片一区随边看 | 超碰免费视频公开观看 | 美女pk精子4 | 亚洲成 人a影院青久在线观看 | 久久国产免费一区二区三区 | 精品成人片深夜 | 日本熟妇乱妇熟色在线电影 | 日韩欧美一区二区中文字幕 | 成年无码av片 | 亚洲破处女 | 俄罗斯6一9泑女网站 | 国产精品.XX视频.XXTV | 国内久经典AAAAA片 | 午夜福利不卡片在线播放免费 |