0
你好我正在使用Visual Studio 2008和asp.net mvc 2.我需要反xss庫來定製由富文本編輯器(輕量級RTE)生成的輸入。 我想使用AntiXss.GetSafeHtmlFragment(input);功能。添加Anti-XSS後VS 2008崩潰
問題是,我參考反xss DLL(它在第一次工作正常,但它比崩潰)後,VS 2008崩潰。
有沒有人如何解決這個問題? 如果沒有人可以指點我一個工作altrenative(我嘗試使用HTML敏捷包,同時允許白名單,但我只設法讓標籤沒有屬性)。
的HTML敏捷性過濾器的代碼 -
public static string Filter(string html, string[] allowedTags)
{
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(html);
StringBuilder buffer = new StringBuilder();
Process(doc.DocumentNode, buffer, allowedTags);
return buffer.ToString();
}
static string[] RemoveChildrenOfTags = new string[] { "script", "style" };
static void Process(HtmlNode node, StringBuilder buffer, string[] allowedTags)
{
switch (node.NodeType)
{
case HtmlNodeType.Text:
buffer.Append(HttpUtility.HtmlEncode(((HtmlTextNode)node).Text));
break;
case HtmlNodeType.Element:
case HtmlNodeType.Document:
bool allowedTag = allowedTags.Contains(node.Name.ToLower());
if (allowedTag)
buffer.AppendFormat("<{0}>", node.Name);
if (!RemoveChildrenOfTags.Contains(node.Name))
foreach (HtmlNode childNode in node.ChildNodes)
Process(childNode, buffer, allowedTags);
if (allowedTag)
buffer.AppendFormat("</{0}>", node.Name);
break;
}
}
謝謝!