Sanitation method from Rick Strahl's blog... http://weblog.west-wind.com/posts/2012/Jul/19/NET-HTML-Sanitation-for-rich-HTML-Input https://github.com/RickStrahl/HtmlSanitizer/blob/master/HtmlSanitizer/HtmlSanitizer/HtmlSanitizer.cs
Beispiel #1
0
        /// <summary>
        /// Cleans up an HTML string and removes HTML tags in blacklist
        /// </summary>
        /// <param name="html">The HTML.</param>
        /// <param name="blackList">The black list.</param>
        /// <returns></returns>
        public static string SanitizeHtml( string html, params string[] blackList )
        {
            var sanitizer = new HtmlSanitizer();

            if ( blackList != null && blackList.Length > 0 )
            {
                sanitizer.BlackList.Clear();
                foreach ( string item in blackList )
                    sanitizer.BlackList.Add( item );
            }

            return sanitizer.Sanitize( html );
        }