2012-01-25 9 views
7
यहाँ

मेरी Default.aspxक्यों संभावित खतरनाक अनुरोध त्रुटि भी ValidateRequest = false

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" ValidateRequest="false" %> 
<html> 
    <head runat="server"> 
     <title>xss demonstration</title> 
    </head> 
    <body> 
     <form id="form1" runat="server"> 
     <div> 
      We are looking for your feedback. 
      <asp:TextBox ID="txtFeedback" runat="server" TextMode="MultiLine" /> 
      <br /> 
      <asp:Button ID="submit" runat="server" Text="Submit" onclick="submit_Click" /> 
      <br /> 
      Comment: 
      <br /> 
      <asp:Literal ID="ltlFeedback" runat="server" /> 
     </div> 
     </form> 
    </body> 
</html> 

Default.aspx.cs

public partial class _Default : System.Web.UI.Page 
{ 
    protected void submit_Click(object sender, EventArgs e) 
    { 
     this.ltlFeedback.Text = this.txtFeedback.Text; 
    } 
} 

है और नीचे है जब मैं में निम्नलिखित आवेदन चलाने के लिए और दर्ज करें पाठ बॉक्स।

<script>alert('Hello')</script> 

मुझे निम्न त्रुटि मिलती है।

एक संभावित खतरनाक Request.Form मूल्य ग्राहक (txtFeedback = "चेतावनी ('हैलो ...") से पता चला था।

मेरा प्रश्न है कारण है कि मैं भले ही यह त्रुटि प्राप्त ValidateRequest पेज में गलत पर सेट है?

उत्तर

12

.NET Framework 4.0 आप web.config में <httpRuntime requestValidationMode="2.0"/> मार्कअप सेट करने के लिए है।

<system.web> 
    <compilation debug="false" targetFramework="4.0" /> 
    <httpRuntime requestValidationMode="2.0"/> 
</system.web> 

संदर्भ आलेख पर एक नज़र डालें - ASP.NET 4 Breaking Changes #1: requestValidationMode cause ValidateRequest=False to fail

+0

यह था ऐसा करने से देखभाल करने के लिए की जरूरत है। धन्यवाद –

0

तुम सिर्फ अपने वेब config

<system.web> 
     <compilation debug="false" targetFramework="4.0" /> 
     <httpRuntime requestValidationMode="2.0"/> 
</system.web> 

में निम्न कोड जोड़ें लेकिन क्रॉस साइट स्क्रिप्टिंग का दौरा पड़ने से इस शिकार हो सकता है आप

संबंधित मुद्दे