Server inconsistencies viewstate / function / server vs development

The code looks something like this:

protected bool IsOKToSend()
{
    bool IsOK = true;        
    lblErrorSending.Visible = false;
    if (txtUserName.Text == "" )
    { 
    lblErrorSending.Text = "Please enter your username before sending.";
    IsOK = false;
    }
    return IsOK;
}

    protected void btnSubmit_Click(object sender, EventArgs e)
{

    if (IsOKToSend())
    {
        adsUser.Insert();
        Response.Redirect("complete.aspx");
    }
    else
    {
        lblErrorSending.Visible = true;
    }
}

      

For some reason, it doesn't work consistently on a real server. Keep in mind that it ALWAYS works on my local development machine and SOMETIMES (about 1 out of 3 attempts) works on a live machine. When it doesn't work on the real server, the pages and all viewpoints are reloaded.

I have a default error in my webconfig file and the page is never redirected to the error page.

The consensus error is easy to fix, but something like that doesn't happen.

Any idea what might make this page someday work and someday not and / or why the viewstate isn't saved when it doesn't work? Why am I not getting the same problem on my local machine?

I tried to combine the two functions to see if the call was calling the outer function but that didn't change anything unfortunately. Also, the IsOK value doesn't seem to have any effect on getting the error or not.

I removed all the code in the page load function to make sure the troubleshooting is correct, but I still get the same issue.

Any idea would be appreciated.

Edit: I was about to post this as is, but I decided to try the following:

protected void btnSubmit_Click(object sender, EventArgs e)
{
    bool IsOK = true;        
    lblErrorSending.Visible = false;
    if (txtUserName.Text == "" )
    { 
        lblErrorSending.Text = "Please enter your username before sending.";
        IsOK = false;
    }
    lblErrorSending.Visible = !IsOK;        
}

      

If I click on the button multiple times, the page will lose its viewstate after several tries, but not always. So the main problem here seems to be the problem with viewstate not working correctly all the time. Any idea?

Thank.

0


source to share


1 answer


I'll take a wild guess here and say you don't use sticky sessions in production and you have multiple web servers. But in development, you only have one server. You are using load balancing and every so often you get kicked to a different server with a different machine key in your maching.config. The app is booming.

Or it’s not at all. :)



If this is a problem, you can disable the viewstate or sync keys in the machine.config file and the problem should go away.

+1


source







All Articles