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

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

主站蜘蛛池模板: 日日射日日操 | 在线观看亚洲免费视频 | 国产午夜精品久久理论片小说 | 色视频色露露永久免费观看 | 精品无码国产AV一区二区三区 | 69日本xxⅹxxxxx18| 伊人久久大香线蕉综合影 | 久久婷婷色一区二区三区 | 亚洲一区二区影院 | 亚洲综合久久一本伊伊区 | 十分钟免费视频大全在线 | 4399日本电影完整版在线观看免费 | 中文有码中文字幕免费视频 | 久久综合色一综合色88 | 日本毛片久久国产精品 | 曰本真人00XX动太图 | 久久国产成人午夜AV影院无码 | 不卡无线在一二三区 | 暖暖视频大全免费观看 | 亚洲嫩草AV永久无码精品无码 | 饥渴的新婚女教师 | 空姐被黑人 苏晓曼 | 国内精品久久久久久西瓜色吧 | 小776论坛| 在线中文字幕亚洲日韩 | 精品淑女少妇AV久久免费 | 黄色三级在线观看 | 青娱乐在线一区 | 欧美成人精品高清在线观看 | 99久久精品费精品蜜臀AV | 成人中文字幕在线观看 | YY8848高清私人影院 | 国产成人在线视频观看 | 午夜精品久久久久久影视riav | 国产亚洲免费观看 | 男女爽爽无遮挡午夜视频在线观看 | 欧美黑人巨大性极品hd欧 | 成人短片迅雷下载 | 少妇伦子伦情品无吗 | 国产人妻人伦精品836700 | 亚洲婷婷天堂综合国产剧情 |