views:

284

answers:

1

Being a bit perplexed about this issue by now, I hope some of you gurus can shed some light on my problem...

I've developed a AJAX-enhanced website, which has been running fine in IE, Chrome and Firefox for a year or so. I use a Timer-control to check for incoming messages every 30 seconds, and this updates an UpdatePanel showing potential new messages.

Now several one of my Firefox users complain about the page refreshing every 30 seconds! I my self cannot reproduce this behaviour, but given the "30 seconds"-description, I cursed my Timer-solution as the culprit.

But now, I'm experiencing this error myself, not in Firefox though, but in Google Chrome! (And only on one of my two computers!) Every 30 seconds the page reloads! But I found that it's not only related to the Timer, because all other asynchronous postbacks to the server within UpdatePanels reloads the entire page as well.

This error has never been experienced in Internet Explorer (to my knowledge).

As I said, this it not only related to the Timer postback, but if it's of interest to anybody the code is like this:

<asp:Timer runat="server" ID="MailCheckTimer" Interval="30000" OnTick="MailChecker_Tick"></asp:Timer>

<asp:UpdatePanel runat="server" ID="MailCheckerUpdatePanel" UpdateMode="Conditional">
    <ContentTemplate>
         <div class="newmail_box" runat="server" id="newmail_box">
           <!-- Content stripped for this example -->
         </div>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="MailCheckTimer" />
    </Triggers>
</asp:UpdatePanel>

In other places of the website I call the client side __doPostBack function directly from JavaScript in relation to an UpdatePanel. Normal behaviour for this call is to updated the referenced UpdatePanel with some content, but now in Chrome this refreshes the entire page! (but again not consistently, and never in IE)

Even the most fundamental UpdatePanel operations like refreshing the content after a button (inside the panel) is clicked, forces the page to reload completely:

<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click"></asp:Button>

And just to torment me further, I only experience this on my public website, and not in my local development environment, making it a tedious affair for me to find the actual cause! :(

Any ideas on why this happens? Why so inconsistently? Has it to do with my UpdatePanel-design? Or does some security setting in Firefox/Chrome that prevent some asynchronous UpdatePanel callbacks?

Any help or idea is highly appreciated!

A: 

OK. I fixed it. For what it worth for any future hair plugging readers, here's what I went through:

I read the article at http://blogs.visoftinc.com/archive/2007/09/23/asp.net-ajax-updatepanel-not-working-common-problems.aspx suggested by TenaciousImpy. Interesting though it seemed, I tried setting the xhtmlConformance attribute to Transistional without any effect. I also tried validating my content with the excellent XHTML Validator Service at validator.w3.org, and even though it did feel good to get my HTML up to shape, it didn't solve my problem. I could still reproduce the error in Chrome, meaning every post back refreshed the entire page... :(

And then by pure chance (and isn't it so often by chance we notice the cause of the most irritating bugs?) I noticed that my Authorization-logic was called on a post back that wasn't suppose to do anything like that. Yes!... Finally a clue that should quickly help me locate cause of my alopecia.

Cutting to the chase here, it shows that, Google Chrome and Firefox, when set to remember the login-information for a specific website, send these information with every single post back. I normally send these to the server, and check for them like this:

string usern = Request["loginusername"] as string;
string password = Request["loginpassword"] as string;

if (!String.IsNullOrEmpty(usern) && !String.IsNullOrEmpty(password))
{
        Authenticate(usern, password, Request["rememberme"] != null);
}

Well, I checked for these parameters early in my MasterPage, and if they existed I assumed the user submitted a login request. I authenticated the user, and for ease of programming I redirected to user the same page (ie. refreshing the page in a logged-in-format and removing the login controls).

Ergo my Timer with a tick every 30 second had its call back parameters extended with the user's login preferences, when having set Chrome or Firefox to remember your latest login and password.

The solution was hereafter simple and obvious. I now only call my Authentication-logic for anonymous users:

if ( Session["user"] == null ) // Check parameter indicating a logged in user
{
      string usern = Request["loginusername"] as string;
      string password = Request["loginpassword"] as string;

      if (!String.IsNullOrEmpty(usern) && !String.IsNullOrEmpty(password))
      {
         Authenticate(usern, password);
      }
}

This allows my site to support the Login-preference memory in Chrome and Firefox.

Alex