views:

98

answers:

1

I have a webpage with 1 label and 2 buttons. One button does a postback generates a random squence of numbers, saves it to the Application object, and calls a method which gets the list from the Application object and writes them to the label. The other obutton just calls the method which gets the numbers and writes them to the label. On page load, I call the same function which gets the values and writes them to the label.

I run the website locally, with 3 browsers (IE, FF, Chrome ) at the same time, and it works as expected. Each browser shows the same value, and they change if one of them calls the Randomize.

On the production server I get different values, sometimes I get no value on IE or FF.

We don't have a load balancer.

Code, it looks ugly, but I've desperately tried every combination just to make it working:

    protected void Page_Load(object sender, EventArgs e)
    {
        show();
    }
    private List<int> AllNums
    {
        get
        {
            List<int> list = new List<int>();
            try
            {
                list = (List<int>)Application["Nums"];
            }
            catch
            {
                list = new List<int>();
            }
            if (list == null)
                list = new List<int>();
            return list;

        }
    }
    protected void btnRandomize_Click(object sender, EventArgs e)
    {
        Random r = new Random();
        int i = r.Next(5, 15);
        List<int> list = new List<int>();
        for (int k = 0; k < i; k++)
            list.Add(r.Next(0, 100));
        Application.Lock();
        Application["Nums"] = list;
        Application.UnLock();
        show();
    }

    private void show()
    {
        StringBuilder sb = new StringBuilder();
        foreach (int o in AllNums)
            sb.AppendLine(o.ToString());
        lblSession.Text = sb.ToString();
    }
A: 

Could it possibly be that the machine.config has set the server session state to Off and you do not have an override in your web.config?

Alternatively it might be the 'zone' that the URL is in. IE acts differently for Intranet, External sites. Add it to the list of trusted sites and try again.

Ryan ONeill