Javascript “Sys.WebForms.PageRequestManagerServerErrorException:状态代码:500”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5178203/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 15:58:46  来源:igfitidea点击:

"Sys.WebForms.PageRequestManagerServerErrorException: status code: 500"

javascriptasp.netwebformsasp.net-ajaxupdatepanel

提问by Basmah

I am using an asp.net text box inside ajax update panel. If I enter &# in the textbox and press Save Button , it gives a javascript error

我在 ajax 更新面板中使用了一个 asp.net 文本框。如果我在文本框中输入 并按 Save Button ,则会出现 javascript 错误

Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 500

Sys.WebForms.PageRequestManagerServerErrorException: 在服务器上处理请求时发生未知错误。服务器返回的状态码为:500

Please help me why this error appears?

请帮我为什么会出现这个错误?

enter image description here

在此处输入图片说明

采纳答案by Vinod Patil

This issue sometimes occurs when you have a control registered as an AsyncPostbackTrigger in multiple update panels.

当您在多个更新面板中将控件注册为 AsyncPostbackTrigger 时,有时会出现此问题。

If that's not the problem, try adding the following right after the script manager declaration:

如果这不是问题,请尝试在脚本管理器声明之后添加以下内容:

<script type="text/javascript" language="javascript">
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
    function EndRequestHandler(sender, args){
        if (args.get_error() != undefined){
            args.set_errorHandled(true);
        }
    }
</script>

There are a few more solutions discussed here: http://forums.asp.net/t/1066976.aspx/9/10

这里讨论了更多的解决方案:http: //forums.asp.net/t/1066976.aspx/9/10

回答by Atanas Korchev

Probably ASP.NET Request Validationkicked in and detected a potentially dangerous request (the &# in the textbox value). This causes an HttpRequestValidationExceptionto be thrown - hence the 500 HTTP code is returned by the UpdatePanel. The way I see it there are two ways to solve this problem:

可能是ASP.NET 请求验证启动并检测到一个潜在的危险请求(文本框值中的 &#)。这会导致HttpRequestValidationException抛出 - 因此 500 HTTP 代码由 UpdatePanel 返回。在我看来,有两种方法可以解决这个问题:

  1. Validate the contents of the textbox and replace any potentially dangerous (HTML like) values.
  2. Disable request validation:

    <%@ Page ValidateRequest="false" %>

  1. 验证文本框的内容并替换任何有潜在危险的(类似 HTML 的)值。
  2. 禁用请求验证:

    <%@ Page ValidateRequest="false" %>

If you choose to disable request validation make sure that the value of this textbox is not output verbatim somewhere else in your application. Make sure you are using HttpUtility.HtmlEncodewhen displaying it in order to avoid XSSissues.

如果您选择禁用请求验证,请确保此文本框的值不会在应用程序的其他地方逐字输出。确保在显示时使用HttpUtility.HtmlEncode以避免XSS问题。