2012-02-16 23 views
0

我試圖找出其中可以用來HtmlAttributeEncode上下文 - 「你好!」我用簡單的嘗試AntiXSS - 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。

任何人都可以請導遊

謝謝

+0

你使用的是什麼asp.net版本? – Aristos 2012-02-16 16:53:20

+0

我正在使用.net 4.0 – iniki 2012-02-16 16:58:08

回答

1

的ASP:!文本框控件自動脫.T ext屬性。請參閱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。

+0

非常感謝分享此列表 - 讓事情變得更加清晰。但我仍然不清楚HtmlAttributeEncode的用法。當你說原始的html時,你的意思是在運行時創建控件,比如'new HyperLink(){Text = Encoder.HtmlEncode(txtUserInput.Text)}。我嘗試過使用其他控件,並且在使用HtmlEncode和HtmlAttributeEncode時找不到任何區別。你的意思是'原始html'的其他內容嗎?你能否給出一個很好的HtmlAttributeEncode的用法。 – iniki 2012-02-16 22:00:26

+0

假設您有以下其中一個: – Erlend 2012-02-17 20:06:05