最近做了一个发表评论的模块。发现有一个BUG:在TextBox中输入"="或"!",提交页面都会出现如下报错。(其他字符似乎都可以)错误代码:
Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.
Details: Error parsing near '<script type='text/j'.
http://localhost/ScriptResource.axd?d=tHconbGLshd8WGRVq289hIhxLJOt7Nrj5jtK2g28s8p6TKlAprYlGzNp7sBKJe5LWxuGQiccSORuoryA1UIjpyAFyGwiyP2OYLGhudYxvn5XrvCYy22IVSqII7Nk2JLW0&t=ffffffff948cd86f
Line 1021在后台程序中,我对输入的异常字符都进行了过滤,但是就算把后台提交的代码删除。这个报错依然存在(也就是说,输入"="或"!",点击提交按钮,后台没有执行任何事件,也会出现上述错误)网上查了一下,说是要把validaterequest设为false,但我试过在Webconfig添加,在页面添加,在Textbox上修改causersValidater属性为false都没用。比较长,希望各位能帮我一下。100分吧

解决方案 »

  1.   

    在web.config中设置customErrors配置节,或者在网页上设置customErrors的方式,设置成Mode='OFF'试试。以前我用过,现在记的不清了。
      

  2.   

    我试了下。
    在TextBox中输入= 和!没有出现你说的错误。但是输入<xml>出现了下列错误:A potentially dangerous Request.Form value was detected from the client (TextBox1="<xml>"). 
    Description: Request Validation has detected a potentially dangerous client input value, and processing of the request has been aborted. This value may indicate an attempt to compromise the security of your application, such as a cross-site scripting attack. You can disable request validation by setting validateRequest=false in the Page directive or in the configuration section. However, it is strongly recommended that your application explicitly check all inputs in this case. Exception Details: System.Web.HttpRequestValidationException: A potentially dangerous Request.Form value was detected from the client (TextBox1="<xml>").
    这个错误确实是可以通过ValidateRequest="false"消除的<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="testWebApp.WebForm4" ValidateRequest="false"%>
      

  3.   

    看看下面的文章有没有帮助:Sys.WebForms.PageRequestManagerParserErrorException - what it is and how to avoid it 
      

  4.   

    在TextBox中输入= 和!是可以 的使用参数化SQL 
    对URL传参进行转义 server.urlEncode
      

  5.   


    看了一下,customErrors设置的是off,好像不是这个原因
      

  6.   


    = =。我试了一下,新建了一个空白的TextBox和按钮,输入!点击也会报错
      

  7.   

    我又试了一下,只有放到母版页里面才会出现报错。单独新建个页面是不会出错的(这是不是说明Webconfig没有问题?)母版页代码大约如下:<%@ Master Language="C#" AutoEventWireup="true" CodeFile="~/master/MasterPage.master.cs" Inherits="master_MasterPage" %>
    <%@ Register Namespace="Intelligencia.UrlRewriter" Assembly="Intelligencia.UrlRewriter" TagPrefix="rewriter" %>
    <%@ Register Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit"  TagPrefix="Toolkit" %> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml">
    <head runat="server">
        <title>网购比价,产品推荐,用户评价的专业导购网站 - 货比三家</title>
        <asp:contentplaceholder id="cphmeta" runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>  
        <meta name="Description" content="" />
        <meta name="Keywords" content="" />
        </asp:contentplaceholder>
        <link rel="shortcut icon" href="/favicon.ico"/>
        <link href="/css/default.css" rel="stylesheet" type="text/css" />
        <script type="text/javascript" src="/script/jquery.js"></script>
    </head>
    <body>
    <rewriter:form ID="Form1" runat="server"> 
    <Toolkit:ToolkitScriptManager ID="sm" runat="server"/>
    <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
      子页面的内容
    </asp:ContentPlaceHolder>
    </rewriter:form> 因为用了rewriter插件。所以用了<rewriter:form> 代替<form>,我也试过使用<form>,也会出错
    <Toolkit:ToolkitScriptManager ID="sm" runat="server"/>,这个我尝试过改成ScriptManager,也不行
      

  8.   

    ValidateRequest="false"这种方法不报错,但是不能录入数据库,对吧,
    其实是使用ajax控件问题,你可以不用微软提供的ajax控件。改用别的方法吧
      

  9.   

    lz在页面提交之前看下源文件,看看文本框的id变化了没,套用母版页时,有时文本框id会变化。如果变化在后台得到文本框值时这样写试试:id.text.Unique