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

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

主站蜘蛛池模板: 国内免费高清视频在线观看 | 美女网站色视频 | 亚洲人成影网站~色 | 国产成人精品视频免费大全 | 草久影院 | 天天躁天天弄天天爱 | 国产日韩在线 | 久久全国免费久久青青小草 | 天堂综合 | 成年女人免费又黄又爽视频 | 99视频精品全部免费观看 | 国模337人人本艺术150p | 欧美一级艳片爽快片 | 国产一区二区三区福利 | 亚洲精品亚洲人成毛片不卡 | 亚洲五月花丁香花社区 | 91精品国产自产在线观看 | 久久国内精品自在自线观看 | 巨大巨粗巨长 黑人长吊视频 | 色久在线 | 久久影视一区 | 天天激情| 青青草国产精品久久久久 | 免费激情网 | 七七七久久久久人综合 | 四虎社区 | 午夜dj影院在线视频观看完整 | 色综合五月激情综合色一区 | 亚洲十欧美十日韩十国产 | 国产精品久久久久久久久ktv | 一二三四视频社区在线中文1 | 精品一区二区三区三区 | 久久婷五月综合 | 久久国产香蕉一区精品 | 国产成人精品亚洲77美色 | 男女免费爽爽爽在线视频 | 国产最强大片免费视频 | 午夜激情视频免费 | 日韩毛片免费视频一级特黄 | 亚瑟成人影院 | 欧美一级久久久久久久久大 |