0

HtmlAttributeEncode を使用できるコンテキストを把握しようとしています -

シンプルな「こんにちは!」でやってみました アラート スクリプトがコントロール属性として設定されているため、HtmlAttributeEncode の動作を確認できましたが、HtmlEncode の代わりに HtmlAttributeEncode を使用できる場所がわかりません。

たとえば、私は

- 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 に答える