首页 > 解决方案 > 如何在类文件中包含 HtmlSanitazationLibrary

问题描述

我已经安装了还安装了 HtmlSanitizationLibrary 的 AntiXssLibrary nuget 包。我可以包含 AntiXssLibrary

`using System.Web.Security.AntiXss;`

然后在我的代码中使用它:

`AntiXssEncoder.HtmlEncode(value, true);`

我尝试对 HtmlSanitizationLibrary 执行相同操作,但 Visual Studio 2019 无法识别类似的 using 语句。如何实现/使用 HtmlSanitizationLibrary?

标签: htmlxsslibraries

解决方案


HtmlSanitizationLibrary 隐藏在一个完全不同的命名空间中,即使它与同一个库一起安装。

using Microsoft.Security.Application;

string html_fragment = "some unsafe html containing XSS";
string safe_html = Sanitizer.GetSafeHtmlFragment(html_fragment);

请参阅https://documentation.help/Microsoft-AntiXSS/documentation.pdf,第 162 - 165 页。


推荐阅读