Antixss GetSafeHtmlFragment编码&作为& amp; [英] Antixss GetSafeHtmlFragment encode & as &

查看:192
本文介绍了Antixss GetSafeHtmlFragment编码&作为& amp;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public static string SanitizeHtml(this string s)

{

返回AntiXss.GetSafeHtmlFragment(s);

}



但是,如果我传入这样的字符串:



black&white





它编码&符号所以它变成:



black&白色



有没有办法阻止它编码这个字符?

public static string SanitizeHtml(this string s)
{
return AntiXss.GetSafeHtmlFragment(s);
}

However, if I pass in a string like this:

black & white


it is encoding the ampersand so it becomes:

black & white

Is there a way of preventing it from encoding this character?

推荐答案

你为什么要这样做? ..Sanitizing HTML意味着...编码特殊字符(可能会在应用程序中为非HTML图层创建问题),HTML渲染仍然可以理解,但其他人不会混淆......

& apm; 是一种称为实体的东西,广泛用于确保在HTML中正确显示特殊字符而不传递这些特殊字符,并且可能会导致麻烦。 。

例如,如果您在CP处添加代码块,您的问题可能包含HTML特殊字符,因此必须对文本进行编码以确保正确显示...同样的方法,以防止XSS攻击编码的内容...为什么不这样做?
Why should you...Sanitizing HTML means exactly that...Encode special characters (that can create problems for non-HTML layers in your application) in a way that HTML rendering still will understand, but others will not confused by...
&apm; is something called entity and used widely to ensure correct display of special characters inside HTML without passing those special characters and - maybe - cause troubles...
For instance if you add code block, here at CP, to your question it may contain HTML special characters so the text have to be encoded to ensure correct display...The same way, to prevent XSS attack the content encoded...Why should you not to do that?


Hello World 。这个酷程序。这是一种化学元素,即H 2 O。
Hello World. This a Cool program. thwere is a chemical element, namely H2O.


这篇关于Antixss GetSafeHtmlFragment编码&作为& amp;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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