2012-01-25 68 views
7

這裏是我的Default.aspx爲什麼有潛在危險的請求錯誤甚至ValidateRequest =假

<%@ 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> 

我得到以下錯誤。從 客戶端(txtFeedback =「警報(「你好......」)檢測

有潛在危險的Request.Form值。

我的問題是,爲什麼我得到這個錯誤,即使ValidateRequest設置爲false在頁面?

回答

0

你只需要添加下面的代碼在你的web配置

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

但這樣做跨站腳本攻擊,你可以犧牲品

相關問題