【问题标题】:What is the difference between html.AttributeEncode vs html.Encode?html.AttributeEncode 与 html.Encode 有什么区别?
【发布时间】:2010-02-11 11:28:03
【问题描述】:

html.AttributeEncode 和 html.Encode 有什么区别?

【问题讨论】:

    标签: asp.net-mvc


    【解决方案1】:

    AttributeEncode 只转换少数字符:

    • "
    • &
    • \

    Encode 执行完整的 HtmlEncode,编码 any 不在 Html 中的字符。

    【讨论】:

    • @daghan 根据文档,它没有,因此如果放置在像title='single quoted' 这样的单引号属性中,您应该使用 AttributeEncode:“结果应该只使用对于双引号中的属性。如果您使用 AntiForgeryToken 方法对单引号中的属性进行编码,则可能会出现安全问题。 msdn.microsoft.com/en-us/library/dd492240.aspx
    猜你喜欢
    • 1970-01-01
    • 2011-02-19
    • 2013-03-14
    • 2018-09-14
    • 2014-01-03
    • 2021-12-22
    • 2017-10-25
    • 2011-06-09
    • 2021-05-11
    相关资源
    最近更新 更多