“Sys.WebForms.PageRequestManagerServerErrorException: status code: 500”

非 Y 不嫁゛ 提交于 2019-12-07 06:42:47

问题


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

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

Please help me why this error appears?


回答1:


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

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




回答2:


Probably ASP.NET Request Validation kicked in and detected a potentially dangerous request (the &# in the textbox value). This causes an HttpRequestValidationException to 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:

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

    <%@ 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.HtmlEncode when displaying it in order to avoid XSS issues.



来源:https://stackoverflow.com/questions/5178203/sys-webforms-pagerequestmanagerservererrorexception-status-code-500

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!