2012-01-25 16 views
7

Ecco il mio Default.aspxerrore di richiesta perché potenzialmente pericoloso anche 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> 

E sotto è 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; 
    } 
} 

Quando eseguo l'applicazione ed entro segue nella casella di testo.

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

Viene visualizzato errore.

Un valore potenzialmente pericoloso Request.Form è stato rilevato dal client (txtFeedback = "alert ('Ciao ...").

mia domanda è perché ottengo questo errore anche se ValidateRequest è impostato su false nella pagina?

risposta

0

basta bisogno di aggiungere seguente codice nel tuo web config

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

ma fate attenzione in questo modo si può essere vittima di cross site scripting attacco

Problemi correlati