ASP. NET Ajax and SYS. webforms. pagerequestmanagerservererrorexception

Source: Internet
Author: User
ASP. NET Ajax and SYS. webforms. pagerequestmanagerservererrorexception

By Ted Jardine

Using ASP. net Ajax extensively in my latest project I 've been sporadically running into the sys. webforms. pagerequestmanagerparsererrorexception. it got to the point that I was contemplating ripping out ASP. net Ajax completely until this known issue had been ironed out. the varous causes for this error are mentioned when different places, but for some samples, go here, here, and here.

Quoting from Eilon Lipton's blog posting, this particle exception is very common and can be caused by any one of the following:

  1. Callto response. Write ():
    By calling response. write () directly you are bypassing the normal rendering mechanism of ASP. net controls. the bits you write are going straight out to the client without further processing (well, mostly ...). this means that updatepanel can't encode the data in its special format.
  2. Response filters:
    Similar to response. Write (), response filters can change the rendering in such a way that the updatepanel won't know.
  3. Httpmodules:
    Again, the same deal as response. Write () and response filters.
  4. Server trace is Enabled:
    If I were going to implement trace again, I 'd do it differently. trace is required tively written out using response. write (), and as such messes up the special format that we use for updatepanel.
  5. Callto server. Transfer ():
    Unfortunately, there's no way to detect that server. transfer () was called. this means that updatepanel can't do anything intelligent when someone callserver. transfer (). the response sent back to the client is the HTML markup from the page to which you transferred. since its HTML and not the special format, it can't be parsed, and you get the error.

The problem was I wasn' t doing any of the above (who uses response. Write in an ASP. NET application these days ?) And I was still sporadically encountering the error-A Show stopping error I might add. an error that is popped up in a javascript warning box completely undecipherable to the end user leaving an empty/useless/castrated updatepanel in its wake. this of course leaves the end user feeling likewise empty/useless/castrated (to say nothing of the developer ).

This post here indicates that there is a problem with the rolemangermodule or any time you set a cookie to the response in an Ajax callback, which can only be solved by doing one of the following:

  1. Disable caching of cookies in the rolemanager.(Yuck)
  2. Handle the application's error event to clear the error from the context selectively(EEK ).
  3. Disable eventvalidation in the web form.
    <% @ Page Language = "C #" enableeventvalidation = "false" %>
    (Gulp)

None of the above are entirely reasonable solutions (especially the last two), and the worst part was that my test page was just a simple contact page that did not change/set roles or cookies, or response. write, or set anything in the session, and wasn' t processing ing any Unicode Character Input, or even requiring a user to be logged in, or writing anything to the trace, or anything beyond the basics. and still it blew up. but only occasionally.

In order to faithfully reproduce the error, I finally determined that it must have something to do with sessions as it wocould only occur if the app pool had recycled and all browser windows had been sed. so, based on one of the comments in one of the above posts, even though I'm not touching Session on one of the problem pages, I tried a hack in one of the problem page's page_load:

Session ["fixajaxsysbug"] = true;

And lo and behold, we're good to go! So even though I am not using Session on the problem page it must be attempting to set the initial session cookie using the update panel callback. so the solution is to make sure the initial session is set before any update panel callback takes place. how this got through into production is beyond me.

So if you're sporadically encountering the sys. webforms. pagerequestmanagerservererrorexception, it cocould be for any of the above reasons or the fact that your dog/CAT/stuffed teddy bear is sitting too close to your monitor. but give the last one a try in every page utilizing Ajax if you're using sessions in your application.

Update: if the problem pages aren't even using session, just turn session off for the page:

<%@ Page EnableSessionState="false" ... %>

Or better yet, set it in your base class to always be off, and turn it on for the pages where you need it on.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.