我的一些模型属性由Allow
Html属性标记.有没有办法自动将AntiXss保护(即仅过滤只允许的标签)应用于这些字段?
解决方法
没有自动的方式.最近你可以做的是获得AntiXss Nuget包.那么你可以在控制器中使用它:
Microsoft.Security.Application.Sanitizer.GetSafeHtml("YourHtml");
要么
Microsoft.Security.Application.Encoder.HtmlEncode("YourHtml");
如果您使用,可以使用它进行解码
Server.HtmlDecode("HtmlEncodedString");
希望这可以帮助.