views:

261

answers:

3

We have a asp.net 2.0 web application that is running on IIS7. It is using web gardens and asp.net state server.

On the page, there are many user controls. On one of the user controls, we have added logging on the button_click event that writes a line in the log whenever that method runs. When we click the button, it only periodically displays the log entry – indicating that the event does not always fire when the button is clicked. We added the logging because we suspected that the button click method was not always running when we clicked the button. The evidence we are seeing seems to confirm our suspicions.

When we remove the web garden and put the site back to a single application pool, the application returns to normal - the button event fires every time. When we run the application on local developer machines, it also works normally.

Has anyone else seen behavior like this? Are there any recommendations on next steps we could take to narrow down the problem?

EDIT: here is the source of the event as requested:

protected void btnSearch_Click(object sender, EventArgs e)
    {
        Log.Error("Searching...");

        SearchArgs args = CtrlToSearchArgs();
        SessionManager.SearchQueryString = Request.QueryString;

        string url = NavigationManager.BuildSearchUrl(args, null, "*** page url removed here ***");

        if (args.PageSize.HasValue)
        {
            SessionManager.SetInSession(SessionManager.Key.SEARCH_PAGESIZE, args.PageSize.Value.ToString());
        }
        else
        {
            SessionManager.SetInSession(SessionManager.Key.SEARCH_PAGESIZE, "10");
        }

        SessionManager.SearchPanelData = url;

        //Set the new args into the session
        SessionManager.SearchControlArgs = args;

        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        Response.Redirect(url);
    }

EDIT # 2: Clarification - this set up is not using multiple servers and is not under a load balancer. We are using multiple AppPools on a single server.

A: 

You probably want to enable sticky sessions on your load balancer.

In the past I have encountered a similar situation where the page was rendered by server A, but the postback was sent to server B causing a failure to validate the postback.

Alternatively, instead of using sticky session you may also want to look into manually setting your MachineKey to be the same for all servers.

Jason Whitehorn
We aren't actually running multiple servers or running under a load balancer. We are just running multiple AppPools on the same server - for performance reasons.
meh
+1  A: 

Set your machine key: http://msdn.microsoft.com/en-us/library/ms998288.aspx

This isn't the only scenario that fails when you don't have the machine key specified i.e. if the app pool is restarted the generated machine key changes and you get failures in anything that depends on it i.e. viewstate validation being one, another one: http://stackoverflow.com/questions/1360078/asp-net-mvc-validation-of-viewstate-mac-failed

eglasius
Just found out that we do have the machine key set.
meh
A: 

Thanks Freddy and Jason for posting answers.

During our troubleshooting process, we decided to revert back to a single app pool. It seemed like a pretty unorthodox way to structure things anyway. However, that didn't fix the problem either.

After going around and around and having a few people go over the code, we finally discovered that we had an object stored in session that contained static variables. We fixed that problem and the site started working as expected.

meh