AntiXss保护的Html模特属性 [英] AntiXss protection Html model properties

查看:94
本文介绍了AntiXss保护的Html模特属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一些模特属性是由AllowHtml属性标记。有什么办法可以自动申请保护AntiXss(即过滤器只允许标签),以这些领域?

Some of my model properties are marked by AllowHtml attribute. Is there any way to automatically apply AntiXss protection (i. e. filter only allowed tags) to these fields?

推荐答案

有没有自动方式。你能做的最接近的是得到AntiXss的NuGet包。然后你就可以在你的控制器下面这样使用它:

There is no automatic way. The closest you can do is to get AntiXss Nuget package. Then you can use it like below in your controller :

  Microsoft.Security.Application.Sanitizer.GetSafeHtml("YourHtml");

  Microsoft.Security.Application.Encoder.HtmlEncode("YourHtml");

如果您使用可以使用去code将其

If you use you can decode it using

  Server.HtmlDecode("HtmlEncodedString");

希望这有助于。

这篇关于AntiXss保护的Html模特属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆