Jim Rogers

Lives in Baton Rouge, LA, with two dogs, one cat, and one lovely wife. I'm a lead developer for GCR Incorporated.

Katrin and Jim

Month List

AJAX Toolkit and Mixed-mode Authentication

by Jim Aug 31, 2007 12:55 PM

Your IIS security settings can cause you to get the dreaded PageRequestManagerParserErrorException.

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 PUB'.

We have a forms authentication site with a single windows authentication "internal login" page; this single page is configured through IIS with anonymous access disabled. The rest of the site has both the anonymous AND windows boxes checked.

If the Integrated Windows Authentication link is not checked on our server, we get the parse exception - but only in IE (everything is fine in Firefox.) Also, if I run Fiddler while accessing the site, it works fine! Presumably Fiddler is doing something that modifies the request, or changes some sort of security negotiation, and this makes the problem go away.

The HTML returned from the request is the whole of the target page, rather than the partial postback that was expected. The problem is not that the request is redirected to a different page. The target page is just failing to reallize that a partial postback was expected, and is rendering the whole page. This can happen when a firewall strips the X-MicrosoftAjax header, but that wasn't happening here; I confirmed that this header did make it to the target page.

So I still don't know exactly what was happening to cause the parse exception, but at least I've got a fix.

Tags:

Code

LinkButton UpdatePanel & onbeforeunload

by Jim Aug 29, 2007 10:13 PM

I'm back to ASP.NET programming having fun with a highly complex user interface.

Our site uses UpdatePanels to bring in new content and we're warning on navigation away from the page - including the back button - by returning a message in onbeforeunload. But all of our ASP.NET LinkButton controls were triggering this warning, even when posting back to the same page. Here's my test page:

<%@ Page Language="vb" Strict="True" %>
<html>
<script>
  var showMessage = true;
  function beforeunload()
  {
    if (showMessage)
      return "You are leaving the test page."
  }
</script>
<body onbeforeunload="return beforeunload();">
  <form runat="server">
    <a href="javascript:function() {showMessage=false;}">Anchor</a>
    <hr />
    <a href="#" onclick="showMessage=false;return false;">Anchor</a>
    <hr />
    <asp:LinkButton runat="server">Default LinkButton</asp:LinkButton>
    <hr />
    <asp:LinkButton runat="server" OnClientClick="showMessage=false;"> 
      Fixed LinkButton</asp:LinkButton>
  </form>
</body>
</html>

This shows the trick to using a LinkButton with an UpdatePanel, or in any situation where the page posts back to itself. The script for turning off the message must be in the onclick, and not in the href's javascript:. The latter works in FireFox but not in IE.

This is because in Internet Explorer, the sequence of events is onclick, onbeforeunload, href, while in Firefox the sequence is onclick, href, onbeforeunload.