亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

ASP.NET過(guò)濾HTML字符串方法總結(jié)

 更新時(shí)間:2014年08月06日 11:26:32   投稿:shichen2014  
這篇文章主要介紹了ASP.NET過(guò)濾HTML字符串方法總結(jié),需要的朋友可以參考下

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

///  <summary>去除HTML標(biāo)記 
///     
///  </summary>   
///  <param name="Htmlstring">包括HTML的源碼</param>   
///  <returns>已經(jīng)去除后的文字</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標(biāo)簽,但把危險(xiǎn)的HTML標(biāo)簽過(guò)濾,如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; 
} 

相關(guān)文章

  • asp.net中頁(yè)面顯示當(dāng)前系統(tǒng)時(shí)間附圖

    asp.net中頁(yè)面顯示當(dāng)前系統(tǒng)時(shí)間附圖

    asp.net如何實(shí)現(xiàn)在頁(yè)面顯示當(dāng)前系統(tǒng)時(shí)間,本文有個(gè)不錯(cuò)的方法,大家可以嘗試操作下,在文章末尾有截圖
    2013-12-12
  • Asp.Net類(lèi)庫(kù)中發(fā)送電子郵件的代碼

    Asp.Net類(lèi)庫(kù)中發(fā)送電子郵件的代碼

    發(fā)送電子郵件是許多需要用戶注冊(cè)的網(wǎng)站的通用功能,通過(guò)正則表達(dá)式我們可以過(guò)濾掉不符合電子郵件格式的輸入,但是仍沒(méi)有辦法確保用戶填寫(xiě)的電子郵件地址一定是他本人真實(shí)有效的電子郵件地址
    2008-09-09
  • asp.net core webapi文件上傳功能的實(shí)現(xiàn)

    asp.net core webapi文件上傳功能的實(shí)現(xiàn)

    這篇文章主要介紹了asp.net core webapi文件上傳功能的實(shí)現(xiàn),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-12-12
  • asp.net實(shí)現(xiàn)輸出xml的方法

    asp.net實(shí)現(xiàn)輸出xml的方法

    這篇文章主要介紹了asp.net實(shí)現(xiàn)輸出xml的方法,涉及asp.net針對(duì)xml節(jié)點(diǎn)的查詢、創(chuàng)建、修改、生成等操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-11-11
  • .NET 數(shù)據(jù)庫(kù)連接池

    .NET 數(shù)據(jù)庫(kù)連接池

    如果您通過(guò)使用另一個(gè) Execute 方法(例如,ExecuteScalar、ExecuteNonQuery 和 ExecuteXMLReader)執(zhí)行查詢
    2008-12-12
  • .NET使用結(jié)構(gòu)體替代類(lèi)提升性能優(yōu)化的技巧

    .NET使用結(jié)構(gòu)體替代類(lèi)提升性能優(yōu)化的技巧

    這篇文章主要介紹了.NET使用結(jié)構(gòu)體替代類(lèi)提升性能優(yōu)化的技巧,使用結(jié)構(gòu)體替代類(lèi)有什么好處呢?在什么樣的場(chǎng)景需要使用結(jié)構(gòu)體來(lái)替代類(lèi)呢?今天的文章為大家一一解答,需要的朋友可以參考下
    2022-05-05
  • WPF依賴屬性用法詳解

    WPF依賴屬性用法詳解

    本文詳細(xì)講解了WPF依賴屬性的用法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-02-02
  • ASP.NET Core Zero模塊系統(tǒng)講解

    ASP.NET Core Zero模塊系統(tǒng)講解

    本文詳細(xì)講解了ASP.NET Core Zero模塊系統(tǒng),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-02-02
  • Asp.Net平臺(tái)下的圖片在線裁剪功能的實(shí)現(xiàn)代碼(源碼打包)

    Asp.Net平臺(tái)下的圖片在線裁剪功能的實(shí)現(xiàn)代碼(源碼打包)

    最近項(xiàng)目中有個(gè)圖片在線裁剪功能,本人查找資料,方法如下:前臺(tái)展現(xiàn)用jquery.Jcrop實(shí)現(xiàn),后臺(tái)使用 System.Drawing.Image類(lèi)來(lái)進(jìn)行裁剪
    2011-10-10
  • asp.net Gridview里添加匯總行

    asp.net Gridview里添加匯總行

    在rowdatabound事件里添加同時(shí)showfooter設(shè)為true
    2008-11-11

最新評(píng)論