0

我试图找出可以使用 HtmlAttributeEncode 的上下文 -

我尝试了简单的“你好!” 警报脚本被设置为控制属性,所以我可以看到 HtmlAttributeEncode 正在运行 - 但看不到我可以在哪里使用 HtmlAttributeEncode 而不是 HtmlEncode。

所以,例如,我有

- a textbox for user input 
  //txtuserInput.Text = <script>alert(document.cookie);</script>

- an anchor control to show user input being set as one of its attribute value 
  In codebehind tried with - 
     myanchorTag.InnerText = txtuserInput.Text
     or
     myanchorTag.Id = txtuserInput.Text

但是我看不到这个脚本正在运行:-(
我已经尝试过 TextBox.Text 属性,但为此我可以使用 HtmlEncode。

任何人都可以请指导。

谢谢!

4

1 回答 1

1

asp:Textbox 控件自动转义 .Text 属性。请参阅http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-components-postattachments/00-08-91-89-96/asp.net_5F00_control_5F00_encoding.htm

在使用非转义控件和构建原始 html 时,您应该使用 HtmlAttributeEncode。

于 2012-02-16T20:47:05.123 回答