ASP.NET Ajax 错误:Sys.WebForms.PageRequestManagerParserErrorException
当我尝试执行任何 Ajax 活动时,我的网站不断出现间歇性错误。 我收到的消息是
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 '
<!DOCTYPE html P'.
所以它显然是某种服务器超时或服务器只是返回损坏的垃圾。 不幸的是,这通常会发生
My website has been giving me intermittent errors when trying to perform any Ajax activities. The message I get is
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 '
<!DOCTYPE html P'.
So its obviously some sort of server timeout or the server's just returning back mangled garbage. This generally, unfortunately not always, happe
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(15)
Eilon Lipton 有一篇出色的博客文章。 它包含许多有关如何避免此错误的提示:
Sys.WebForms.PageRequestManagerParserErrorException - 它是什么以及如何避免它
也请阅读评论。 有人有同样问题的评论:“我解决了它,改变了 IIS 上应用程序池的服务器空闲时间。它只有 5,所以我增加了它,现在可以工作了。”
“UpdatePanel 控件使用异步回发来控制渲染页面的哪些部分。它在客户端上使用一大堆 JavaScript 并在服务器上使用一大堆 C# 来实现这一点。
异步回发与常规回发完全相同,除了一件重要的事情:异步回发与常规页面经历相同的生命周期事件(这是我经常被问到的问题)。
仅在渲染阶段事情变得不同了。我们只捕获我们关心的 UpdatePanel 的渲染,并使用特殊格式将其发送到客户端。此外,我们还发送一些其他信息,例如隐藏的页面标题。表单值、表单操作 URL 和脚本列表。”
该错误的最常见原因:
There is an excellent blog entry by Eilon Lipton. It contains of lot of tips on how to avoid this error:
Sys.WebForms.PageRequestManagerParserErrorException - what it is and how to avoid it
Read the comments too. There is a comment of somebody with the same problem: "I solved it changing server idle time of my app pool on IIS. It was only 5, so I incremented it and now works."
"The UpdatePanel control uses asynchronous postbacks to control which parts of the page get rendered. It does this using a whole bunch of JavaScript on the client and a whole bunch of C# on the server.
Asynchronous postbacks are exactly the same as regular postbacks except for one important thing: the rendering. Asynchronous postbacks go through the same life cycles events as regular pages (this is a question I get asked often).
Only at the render phase do things get different. We capture the rendering of only the UpdatePanels that we care about and send it down to the client using a special format. In addition, we send out some other pieces of information, such as the page title, hidden form values, the form action URL, and lists of scripts."
Most common reasons for that error:
回发时可能发生错误。 在这种情况下,您可以通过将 PostBackTrigger 添加到 updatepanel 并引用导致问题的按钮来查看有关错误的详细信息:
Probably there is an error occuring on post back. In this case, you can view the details about the error by adding a PostBackTrigger to your updatepanel and referencing the button which causes the problem:
我遇到过这种情况,并且答案中列出的原因均不适用。 直到我完全禁用 AJAX 后,我才找到问题的根源。 发现代码正在将一个对象保存到包含不可序列化对象的 ViewState 中。 我使对象可序列化,它再次开始工作。
I had this happen to me and none of the causes on the list in the answer applied. I didn't find the root of the problem until I disabled my AJAX altogether. Discovered that the code was saving an object to the ViewState that contained an unserializable object. I made the object serializable and it started working again.
问题:重定向页面时会发生 Sys.WebForms.PageRequestManagerParserErrorException,假设在 aspxAjax 中单击 UpdatePanel 内的按钮。
解决方案:
在使用更新面板的 aspx 页面中添加一个“GoTo”按钮,并将其添加到更新面板之外
在您的代码中将您刚刚注册的用户ID分配给会话变量,例如数据库或UsernameField中的
Session["UseridJustregistered"]=Id
Respose.Redirect("regSucces.aspx?urlid='" + Session["UseridJustregistered"] + " '");
检查是否
Session["UseridJustregistered"]
是否为 null这是旧的经典 ASP 方式,可以解决我们的问题问题,当微软找到解决方案时,我们可以通过这种方式解决它。
Problem: Sys.WebForms.PageRequestManagerParserErrorException will occur when redirecting your page, lets say button click inside UpdatePanel in aspxAjax.
SOlution:
Add a "GoTo" button in your aspx page where update panel is using and add it outside Update panel
In your code assign ur just registered userID to session variable , say
Session["UseridJustregistered"]=Id
from DB or UsernameFieldRespose.Redirect("regSucces.aspx?urlid='" + Session["UseridJustregistered"] + "'");
Check if
Session["UseridJustregistered"]
is null or notThis is OLD Classic ASP way which can solve our problem , by the time Microsoft find a solution we can tackle it this way.
我解决了这个完全相同的问题,删除了
IIS
HTTP Headers
选项卡中Custom HTTP Headers
部分的Content-Type:
/代码>。 这破坏了页面的编码,并以某种方式影响了 Ajax。我在
IIS
中配置的Content-Type
将编码设置为ISO-8859-1
。I solved this exact same problem removing the
Content-Type:
form theCustom HTTP Headers
section in theHTTP Headers
tab inIIS
. This was breaking the encoding of the page and somehow it affected Ajax in general.The
Content-Type
I had configured inIIS
was setting the encoding toISO-8859-1
.这可能有点棘手,但它解决了我的问题。 我没有任何常见的错误原因,所以我只是在页面加载中添加了这个创可贴:
This may be a little hacky, but it solved the issue for me. I didn't have any of the common reasons for the error, so I just put in this band-aid in the page load:
我通过删除错误嵌套的 UpdatePanel 解决了同样的问题。
I solved this same problem by removing mistakenly-nested UpdatePanels.
我终于解决了同一问题的变体。 我试图在网络表单中的 2 个列表框之间复制/移动选定的值。 就我而言,我必须在第二次执行该操作之前专门调用 {listbox}.ClearSelection() 。
显然,出现此问题/错误消息的原因有多种。
I finally solved my variant of this same problem. I was attempting to copy/move a selected value between 2 listboxes in a webform. In my case, I had to specifically call {listbox}.ClearSelection() prior performing the action the 2nd time around.
So obviously this problem/error message can occur for a multitude of reasons.
将应用程序池从集成更改为 asp.net classic 解决了我的问题。
Change of the app pool FROM INTEGRATED to asp.net classic solved the problem for me.
在我们的例子中,问题是由重写代理引起的。 重写修改了更新面板响应的内容。 但这个响应也包含原始大小。 重写机制无法知道响应中的几个字节实际上包含原始响应大小,因此也应该对其进行修改。
更新面板响应如下所示:
30502
是正在更新的内容的原始大小。 重写引擎修改了输出,但大小保持不变=> 解析器错误异常。我看不出如何从客户端解决这个问题。 我们需要知道内容到底是如何修改的,然后在 UpdatePanel ClientScript 开始处理它之前以某种方式更改响应的大小。
In our case the issue was caused by a rewriting proxy on the way. The rewrite modified the content of the update panel response. But this response also contains original size. The rewriting mechanism cannot know that few bytes of the response actually contains original response size and it should also be modified.
The update panel response starts like this:
The
30502
is original size of the content which is being updated. Rewriting engine modifies the output, but the size stays unchanged => parser error exception.I don't see a way how to overcome this issue from the client side. We would need to know how exactly was the content modified and then somehow change the size in the response before UpdatePanel ClientScript starts processing it.
我也遇到这个错误。 “user1097991”报告的解决方案解决了它一段时间(我在视图状态上使用非序列化对象)
但后来错误再次返回,现在以随机方式。 经过一番搜索后,我得到了答案:视图状态变得太大并且被截断。 我禁用了网格和菜单上的一些视图状态,并且问题没有再次出现。
I also got this error. The solution reported by "user1097991" solved it for a while (I was using not-serialized objects on viewstate)
But later the error returned again, now in a random fashion. After some search I got the answer: the viewstate was becoming too large and was been truncated. I disable some viewstates on grids and menus and the problem haven't shown again.
我发现我的问题与 GridView 的数据绑定中呈现的空字符有关。 响应的预期长度与响应文本的实际长度不匹配,导致抛出错误。 一旦我修复了数据库中的数据,我就不再收到错误了。 最终的解决方案是清理在 RowDataBound 事件期间呈现的文本。
查看数据库,我看不到错误数据,因为如果字符串中包含 nul 字符 (Char(0)),SQL Server 2008 不会显示文本。 在 GridView 的 RowDataBound 事件中,我添加了代码以针对其中包含特殊字符的任何文本引发异常。 这就是我找到包含 nul 字符的记录的方法。
tl;dr - 检查渲染的 html 中是否有 nul 字符。
I found that my issue was related to a nul character being rendered in the databinding of a GridView. The expected length of the response wasn't matching the actual length of the response text which resulted in the error being thrown. Once I fixed the data in the database, I no longer got the error. The ultimate fix will be to sanitize the text getting rendered during the RowDataBound event.
Looking through the database, I couldn't see the bad data since SQL Server 2008 doesn't show the text if the nul character (Char(0)) is in the string. In the RowDataBound event of my GridView, I added code to throw an exception for any text that had special characters in it. This is how I found the record that contained the nul characters.
tl;dr - Check for nul characters in the rendered html.
另请注意,这可能是由于对通过部分回发渲染到页面的内容进行了不正确的 html 编码造成的。
Please also be aware that this can be caused by not properly html encoding what you may be rendering to the page through partial postbacks.
我有完全相同的错误。
对我来说,
web.config(.Net 3.5 应用程序)的 httpModules 部分缺少
此错误似乎可能与许多不同的事情有关。
I had exactly the same error.
For me it was
Missing in the httpModules section of web.config (.Net 3.5 app)
This error seems to may be related to many various things.
将 ScriptMode 更新为“Release”
Update the ScriptMode to "Release"