2015-11-30 17 views
0

當用戶在模式彈出窗口的asp.net文本框控件中輸入<>符號時,回發時會引發運行時錯誤。我知道,在過去的很多回答這類問題是設置ValidateRequest =「假」,但是我不想設置在擔心可能會阻止其他攻擊禁用安全功能。從asp文本框中移除HTML標籤,鏈接到確認按鈕擴展程序而不設置ValidateRequest =「false」

的用戶希望能夠複製和有時含有<>標籤粘貼電子郵件文本,但他們不介意,如果標籤被刪除,他們只是想在複製和粘貼,然後提交它們被自動刪除服務器處理的表單。

任何人都可以提供此類問題的解決方案的例子嗎?如果因爲用戶喜歡什麼是一些替代解決方案而無法完成?謝謝。

回答

0

所以跨欄我是模態彈出按鈕,我想火JS之一,是有聯繫的,這不是讓它火災的AJAX確認鍵擴展。

我不得不使用EMCA腳本來修改確認鍵擴展的行爲屬性,包括在該腳本的JS功能。最後我做了檢查,以確保該擴展是不是null作爲根據情況我可能會或可能不會實例化控制。

這是我最後的解決辦法:

在aspx頁面開頭的內容標籤後,我把我的腳本:

<script type="text/ecmascript"> 
    Sys.Application.add_load(wireEvents); 

    function wireEvents() { 
     var behavior = $find("confirmBehavior"); 
     if (behavior !== null) 
     { behavior.add_showing(formatText); } 
    } 

    function formatText() { 
     var newValue = document.getElementById('<%=txtStatusComment.ClientID%>').value.replace(/[<>]+/g, ""); 
     document.getElementById('<%=txtStatusComment.ClientID%>').value = newValue; 
    } 
    </script> 

隨後的按鈕,我做了以下內容:

<asp:Button ID="btnSaveStatus" runat="server" CssClass="button" OnClick="btnSaveStatus_Click" Text="Save" OnClientClick ="formatText();" /> 
           <asp:Button ID="btnCancelStatus" runat="server" CssClass="button" OnClick="btnCancelStatus_Click" Text="Cancel" OnClientClick ="formatText();" /> 
           <cc1:ConfirmButtonExtender ID="btnSaveStatus_ConfirmButtonExtender" BehaviorID="confirmBehavior" runat="server" DisplayModalPopupID="modalPopupExtender3" Enabled="true" TargetControlID="btnSaveStatus"> 
           </cc1:ConfirmButtonExtender> 

希望這有助於同樣的問題任何人!

相關問題