简体   繁体   English

UpdatePanel内PostBack上的HttpRequestValidationException

[英]HttpRequestValidationException on PostBack within UpdatePanel

HttpRequestValidationException occurs when I try post when txtBulletin contains any HTML, like " Hello<br />World " 当我尝试发布时txtBulletin包含任何HTML,例如“ Hello<br />World ”时,就会发生HttpRequestValidationException

Bulletin.aspx 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 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
    }
}

I have no idea how to bypass this, or why it evens does the validation for me. 我不知道如何绕过它,或者它为什么还要为我做验证。 On error, the page no longer handles any PostBack events until I refresh the page. 错误时,页面将不再处理任何PostBack事件,直到刷新页面为止。

ASP.NET checks POST values for potentially dangerous strings. ASP.NET检查POST值中是否存在潜在的危险字符串。 This is done to prevent DoS attacks and the like. 这样做是为了防止DoS攻击等。

To disable this, you'll need to edit the web.config file. 要禁用此功能,您需要编辑web.config文件。 Make sure the following element exists under <system.web> : 确保以下元素存在于<system.web>

<pages validateRequest="false" />

Alternatively, to turn off request validation on a page-by-page basis, set the ValidateRequest property to false in the @Page declaration at the top of the ASPX page in question. 或者,要逐页关闭请求验证,请在所讨论的ASPX页面顶部的@Page声明中将ValidateRequest属性设置为false。

EDIT : Included details about how to turn request validation off for specific pages. 编辑 :包括有关如何关闭特定页面的请求验证的详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM