Have you been worried about how to prevent XSS attacks? Try nhtmlfilter. I think it is what you want ..
Recently, a new small company is very weak in. NET web development. The underlying framework and basic library are not perfect. It is also an Internet application, so security always needs to be considered. One small problem I want to solve today is to filter out the scripts in the HTML text uploaded by the user. I checked on the Internet and found no suitable C #-based processing. In Java projects, I may choose jsoup, htmlfilter to deal with HTML dangerous scripts (in fact, I used to do Java Development). In desperation, I will refer to the htmlfilter of Java version.CodeWrite the C # version.
Usage
Nhtmlfilter target = new nhtmlfilter (); string input = "<div> DD </div> <a id = \" testid \ "href = \" http://code.google.com/p/nhtmlfilter\ "> nhtmlfilter </a> "; string expected = "DD <a href = \" http://code.google.com/p/nhtmlfilter\ "> nhtmlfilter </a>"; string actual; actual = target. filter (input );
Applicable labels and tag attributesProgramPreparation and simple encapsulation can be used for your project.
Code browsing address
Https://code.google.com/p/nhtmlfilter/source/browse/trunk/NHtmlFilter/NHtmlFilter.cs
Code project ..
Https://code.google.com/p/nhtmlfilter/downloads/list (Google Code may be walled out ..)
Download from this site
Http://files.cnblogs.com/weirhp/NHtmlFilter1.0.rar
Other versions written by others: Java PHP
Download and use it. It is released based on the MIT protocol .. Just be happy .. If you have any questions, study them together.
This article is original to the author.
Http://www.cnblogs.com/weirhp/archive/2011/10/03/NHtmlFilter.html
Please repost the famous source. Thank you.
Weirhp@gmail.com