ASP。NET Ajax错误:Sys.WebForms.PageRequestManagerParserErrorException

时间:2022-10-13 13:33:26

My website has been giving me intermittent errors when trying to perform any Ajax activities. The message I get is

在尝试执行任何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'.

So its obviously some sort of server timeout or the server's just returning back mangled garbage. This generally, unfortunately not always, happe

显然这是某种服务器超时或者服务器返回损坏的垃圾。不幸的是,这通常会发生

14 个解决方案

#1


22  

There is an excellent blog entry by Eilon Lipton. It contains of lot of tips on how to avoid this error:

Eilon Lipton有一个很棒的博客条目。它包含了许多关于如何避免这个错误的提示:

Sys.WebForms.PageRequestManagerParserErrorException - what it is and how to avoid it

Sys.WebForms。PageRequestManagerParserErrorException—它是什么以及如何避免它

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."

阅读评论。有一个人也有同样的问题:“我解决了它,改变了我在IIS上的应用程序池的服务器空闲时间。”它只有5,所以我增加了它,现在可以工作了。

"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.

UpdatePanel控件使用异步回发来控制显示页面的哪些部分。它在客户机上使用大量的JavaScript,在服务器上使用大量的c#。

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."

只有在渲染阶段,事情才会变得不同。我们只捕获我们关心的UpdatePanels的呈现,并使用一种特殊的格式将其发送到客户机。此外,我们还发送其他一些信息,如页面标题、隐藏的表单值、表单动作URL和脚本列表。

Most common reasons for that error:

造成这种错误的最常见原因是:

  1. Calls to Response.Write():
  2. 调用Response.Write():
  3. Response filters
  4. 响应过滤器
  5. HttpModules
  6. HttpModules
  7. Server trace is enabled
  8. 服务器启用跟踪
  9. Calls to Server.Transfer()
  10. 调用Server.Transfer()

#2


9  

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:

很可能在回帖上出现了错误。在这种情况下,您可以通过在updatepanel中添加PostBackTrigger并引用导致问题的按钮来查看错误的详细信息:

    <asp:updatepanel ID="updatepanel1" runat="server">
        <Triggers>
            <asp:PostBackTrigger ControlID="button1" /> 
        </Triggers>
        <ContentTemplate>

        </ContentTemplate>
    </asp:updatepanel>

#3


4  

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.

我遇到过这种情况,但我的答案中没有任何原因。直到禁用了AJAX,我才找到问题的根源。发现代码将对象保存到包含不可序列化对象的ViewState中。我使对象可序列化,它又开始工作了。

#4


1  

I solved this exact same problem removing the Content-Type: form the Custom HTTP Headers section in the HTTP Headers tab in IIS. This was breaking the encoding of the page and somehow it affected Ajax in general.

我解决了同样的问题,删除内容类型:在IIS的HTTP header选项卡中形成自定义HTTP header。这破坏了页面的编码,并在某种程度上影响了Ajax。

The Content-Type I had configured in IIS was setting the encoding to ISO-8859-1.

我在IIS中配置的内容类型将编码设置为ISO-8859-1。

#5


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:

这可能有点小题大做,但它解决了我的问题。我没有任何常见的错误原因,所以我只是把这个创可贴放在页面上:

if (Session.SessionID == "")
{
    Page.Session.Add("SessionID", Session.SessionID);
}

#6


1  

Problem: Sys.WebForms.PageRequestManagerParserErrorException will occur when redirecting your page, lets say button click inside UpdatePanel in aspxAjax.

问题:Sys.WebForms。PageRequestManagerParserErrorException将在重定向您的页面时发生,让我们在aspxAjax中的UpdatePanel中单击按钮。

SOlution:

解决方案:

  1. Add a "GoTo" button in your aspx page where update panel is using and add it outside Update panel

    在您的aspx页面中添加一个“GoTo”按钮,更新面板正在使用,并将其添加到外部更新面板中。

  2. In your code assign ur just registered userID to session variable , say Session["UseridJustregistered"]=Id from DB or UsernameField

    在您的代码中,将您刚刚注册的userID分配给会话变量,例如session [" useridjustregi注册"]=Id from DB或UsernameField

  3. Respose.Redirect("regSucces.aspx?urlid='" + Session["UseridJustregistered"] + "'");

    Respose.Redirect(“regSucces.aspx ?urlid='" + Session[" useridju注册用户"]+ " "];

  4. Check if Session["UseridJustregistered"] is null or not

    检查会话[" useridjustregi注册"]是否为空

This is OLD Classic ASP way which can solve our problem , by the time Microsoft find a solution we can tackle it this way.

这是一种传统的ASP方法,它可以解决我们的问题,当微软找到一个解决方案时,我们可以用这种方法来解决它。

#7


1  

I solved this same problem by removing mistakenly-nested UpdatePanels.

我通过删除错误嵌套的UpdatePanels解决了这个问题。

#8


1  

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.

我终于解决了这个问题的变体。我试图在一个webform中的两个列表框中复制/移动一个选定的值。在我的例子中,我必须特别地调用{listbox}. clearselection()在第二次执行操作之前。

So obviously this problem/error message can occur for a multitude of reasons.

因此很明显,这个问题/错误消息可能有很多原因。

#9


1  

Change of the app pool FROM INTEGRATED to asp.net classic solved the problem for me.

从集成到asp.net的应用程序池的变化解决了我的问题。

#10


1  

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:

更新面板响应如下所示:

1|#||4|30502|updatePanel|pnlUpdate| ...

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.

30502是正在更新的内容的原始大小。重写引擎修改输出,但是大小保持不变=>解析器错误异常。

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.

我不知道如何从客户端解决这个问题。我们需要知道内容是如何修改的,然后在UpdatePanel ClientScript开始处理它之前,以某种方式更改响应中的大小。

#11


0  

I also got this error. The solution reported by "user1097991" solved it for a while (I was using not-serialized objects on viewstate)

我也得到了这个错误。由“user1097991”报告的解决方案解决了它一段时间(我在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.

但后来错误再次出现,现在是随机的。在搜索之后,我得到了答案:viewstate变得太大了,被截断了。我在网格和菜单上禁用了一些viewstate,问题也没有再次出现。

#12


0  

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.

我发现我的问题与在GridView的数据库中呈现的nul字符有关。响应的预期长度与响应文本的实际长度不匹配,从而导致抛出错误。一旦我修复了数据库中的数据,我就不再得到错误。最终的解决方案是对在RowDataBound事件期间呈现的文本进行清理。

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.

查看数据库时,我看不到坏数据,因为如果nul字符(Char(0)在字符串中,SQL Server 2008不会显示文本。在我的GridView的RowDataBound事件中,我添加了一些代码,以对其中包含特殊字符的任何文本抛出异常。我就是这样找到包含nul字符的记录的。

tl;dr - Check for nul characters in the rendered html.

检查呈现的html中的nul字符。

#13


0  

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.

还请注意,这可能是由于不正确的html编码导致的,您可能通过部分回发呈现给页面。

#14


0  

I had exactly the same error.

我也有同样的错误。

For me it was

对我来说,这是

<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

Missing in the httpModules section of web.config (.Net 3.5 app)

在web的httpModules部分中丢失。配置(。Net 3.5应用程序)

This error seems to may be related to many various things.

这个错误似乎与许多不同的事情有关。

#1


22  

There is an excellent blog entry by Eilon Lipton. It contains of lot of tips on how to avoid this error:

Eilon Lipton有一个很棒的博客条目。它包含了许多关于如何避免这个错误的提示:

Sys.WebForms.PageRequestManagerParserErrorException - what it is and how to avoid it

Sys.WebForms。PageRequestManagerParserErrorException—它是什么以及如何避免它

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."

阅读评论。有一个人也有同样的问题:“我解决了它,改变了我在IIS上的应用程序池的服务器空闲时间。”它只有5,所以我增加了它,现在可以工作了。

"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.

UpdatePanel控件使用异步回发来控制显示页面的哪些部分。它在客户机上使用大量的JavaScript,在服务器上使用大量的c#。

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."

只有在渲染阶段,事情才会变得不同。我们只捕获我们关心的UpdatePanels的呈现,并使用一种特殊的格式将其发送到客户机。此外,我们还发送其他一些信息,如页面标题、隐藏的表单值、表单动作URL和脚本列表。

Most common reasons for that error:

造成这种错误的最常见原因是:

  1. Calls to Response.Write():
  2. 调用Response.Write():
  3. Response filters
  4. 响应过滤器
  5. HttpModules
  6. HttpModules
  7. Server trace is enabled
  8. 服务器启用跟踪
  9. Calls to Server.Transfer()
  10. 调用Server.Transfer()

#2


9  

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:

很可能在回帖上出现了错误。在这种情况下,您可以通过在updatepanel中添加PostBackTrigger并引用导致问题的按钮来查看错误的详细信息:

    <asp:updatepanel ID="updatepanel1" runat="server">
        <Triggers>
            <asp:PostBackTrigger ControlID="button1" /> 
        </Triggers>
        <ContentTemplate>

        </ContentTemplate>
    </asp:updatepanel>

#3


4  

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.

我遇到过这种情况,但我的答案中没有任何原因。直到禁用了AJAX,我才找到问题的根源。发现代码将对象保存到包含不可序列化对象的ViewState中。我使对象可序列化,它又开始工作了。

#4


1  

I solved this exact same problem removing the Content-Type: form the Custom HTTP Headers section in the HTTP Headers tab in IIS. This was breaking the encoding of the page and somehow it affected Ajax in general.

我解决了同样的问题,删除内容类型:在IIS的HTTP header选项卡中形成自定义HTTP header。这破坏了页面的编码,并在某种程度上影响了Ajax。

The Content-Type I had configured in IIS was setting the encoding to ISO-8859-1.

我在IIS中配置的内容类型将编码设置为ISO-8859-1。

#5


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:

这可能有点小题大做,但它解决了我的问题。我没有任何常见的错误原因,所以我只是把这个创可贴放在页面上:

if (Session.SessionID == "")
{
    Page.Session.Add("SessionID", Session.SessionID);
}

#6


1  

Problem: Sys.WebForms.PageRequestManagerParserErrorException will occur when redirecting your page, lets say button click inside UpdatePanel in aspxAjax.

问题:Sys.WebForms。PageRequestManagerParserErrorException将在重定向您的页面时发生,让我们在aspxAjax中的UpdatePanel中单击按钮。

SOlution:

解决方案:

  1. Add a "GoTo" button in your aspx page where update panel is using and add it outside Update panel

    在您的aspx页面中添加一个“GoTo”按钮,更新面板正在使用,并将其添加到外部更新面板中。

  2. In your code assign ur just registered userID to session variable , say Session["UseridJustregistered"]=Id from DB or UsernameField

    在您的代码中,将您刚刚注册的userID分配给会话变量,例如session [" useridjustregi注册"]=Id from DB或UsernameField

  3. Respose.Redirect("regSucces.aspx?urlid='" + Session["UseridJustregistered"] + "'");

    Respose.Redirect(“regSucces.aspx ?urlid='" + Session[" useridju注册用户"]+ " "];

  4. Check if Session["UseridJustregistered"] is null or not

    检查会话[" useridjustregi注册"]是否为空

This is OLD Classic ASP way which can solve our problem , by the time Microsoft find a solution we can tackle it this way.

这是一种传统的ASP方法,它可以解决我们的问题,当微软找到一个解决方案时,我们可以用这种方法来解决它。

#7


1  

I solved this same problem by removing mistakenly-nested UpdatePanels.

我通过删除错误嵌套的UpdatePanels解决了这个问题。

#8


1  

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.

我终于解决了这个问题的变体。我试图在一个webform中的两个列表框中复制/移动一个选定的值。在我的例子中,我必须特别地调用{listbox}. clearselection()在第二次执行操作之前。

So obviously this problem/error message can occur for a multitude of reasons.

因此很明显,这个问题/错误消息可能有很多原因。

#9


1  

Change of the app pool FROM INTEGRATED to asp.net classic solved the problem for me.

从集成到asp.net的应用程序池的变化解决了我的问题。

#10


1  

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:

更新面板响应如下所示:

1|#||4|30502|updatePanel|pnlUpdate| ...

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.

30502是正在更新的内容的原始大小。重写引擎修改输出,但是大小保持不变=>解析器错误异常。

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.

我不知道如何从客户端解决这个问题。我们需要知道内容是如何修改的,然后在UpdatePanel ClientScript开始处理它之前,以某种方式更改响应中的大小。

#11


0  

I also got this error. The solution reported by "user1097991" solved it for a while (I was using not-serialized objects on viewstate)

我也得到了这个错误。由“user1097991”报告的解决方案解决了它一段时间(我在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.

但后来错误再次出现,现在是随机的。在搜索之后,我得到了答案:viewstate变得太大了,被截断了。我在网格和菜单上禁用了一些viewstate,问题也没有再次出现。

#12


0  

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.

我发现我的问题与在GridView的数据库中呈现的nul字符有关。响应的预期长度与响应文本的实际长度不匹配,从而导致抛出错误。一旦我修复了数据库中的数据,我就不再得到错误。最终的解决方案是对在RowDataBound事件期间呈现的文本进行清理。

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.

查看数据库时,我看不到坏数据,因为如果nul字符(Char(0)在字符串中,SQL Server 2008不会显示文本。在我的GridView的RowDataBound事件中,我添加了一些代码,以对其中包含特殊字符的任何文本抛出异常。我就是这样找到包含nul字符的记录的。

tl;dr - Check for nul characters in the rendered html.

检查呈现的html中的nul字符。

#13


0  

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.

还请注意,这可能是由于不正确的html编码导致的,您可能通过部分回发呈现给页面。

#14


0  

I had exactly the same error.

我也有同样的错误。

For me it was

对我来说,这是

<add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>

Missing in the httpModules section of web.config (.Net 3.5 app)

在web的httpModules部分中丢失。配置(。Net 3.5应用程序)

This error seems to may be related to many various things.

这个错误似乎与许多不同的事情有关。