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

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

主站蜘蛛池模板: 久久久久久久久免费影院 | 一道本色 | 一区二区三区免费视频网站 | 国产成人精品视频在放 | 岛国在线最新 | 久久国产福利 | 国产成人久久精品激情 | 综合色网站 | 国产激情久久久久影 | 国产精品第一页在线观看 | 日韩专区亚洲国产精品 | 五月婷婷亚洲综合 | 黄色在线观看免费 | 欧美成人精品久久精品 | 国产精品黄大片在线播放 | 国产成人在线小视频 | 国产精品2020在线看亚瑟 | 爽爽影院色黄网站在线观看 | 国产网站精品 | 国内一级毛片 | 国产一区二区精品久久凹凸 | 一区二区视频在线播放 | 久久精品国产无限资源 | 国产视频自拍一区 | 国产高清第一页 | 欧美一区色 | 第一页综合| 亚洲激情综合在线 | 国产黄色小视频 | 日本伊人色综合网站 | 久久久综合久久 | 九九精彩视频在线观看视频 | 日韩精品一区二区三区中文在线 | 国产成人 免费观看 | 99在线视频免费观看 | 四虎国产精品永久在线播放 | 91大神在线精品网址 | 在线一区观看 | 午夜伦伦 | 国产馆手机在线观看 | 久久免费视频一区 |