代码之家  ›  专栏  ›  技术社区  ›  sshow Darron Smith

UpdatePanel内回发时的HttpRequestValidationException

  •  0
  • sshow Darron Smith  · 技术社区  · 17 年前

    HttpRequestValidationException 在我尝试发布时发生 txtBulletin 包含任何HTML,如“ Hello<br />World "

    Bulletin.aspx

    <asp:UpdatePanel ID="upContent" runat="server" UpdateMode="Always">
        <ContentTemplate>
            <div class="content bulletin-content">
                <asp:TextBox ID="txtBulletin" runat="server"
                             TextMode="MultiLine" />
                <div class="bulletin-edit">
                    <asp:ImageButton ID="btnSaveBulletin" runat="server" 
                             ImageUrl="~/images/icons/check.gif"
                             CommandName="SaveChanges"
                             OnCommand="btnEditBulletin_Click"
                             Visible="false" />
                </div>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
    

    Bulletin.aspx.cs

    protected void btnEditBulletin_Click(object sender, CommandEventArgs e)
    {
        if (e.CommandName == "Edit")
        {
            // Do something
        }
        else if (e.CommandName == "SaveChanges")
        {
            // Do something
        }
        else if (e.CommandName == "Cancel")
        {
            // Do something
        }
    }
    

    我不知道如何绕过这个,也不知道为什么它会为我做验证。出错时,在我刷新页面之前,页面不再处理任何回发事件。

    1 回复  |  直到 17 年前
        1
  •  4
  •   David Andres    17 年前

    ASP.NET检查POST值是否存在潜在的危险字符串。这样做是为了防止DoS攻击等。

    要禁用此功能,您需要编辑web.config文件。确保下面的元素存在于 <system.web>

    <pages validateRequest="false" />
    

    或者,要逐页关闭请求验证,请在相关ASPX页面顶部的@page声明中将ValidateRequest属性设置为false。

    编辑