Static variable reset after some time

I have a simple access control class that allows me to check that the user has permissions, then he interacts with a static variable:

private static bool canUpdate = false;

This is used when loading a protected void Page_Load page (object sender, EventArgs e)

{
    if (!Page.IsPostBack)
    {
        AccessControl I = new AccessControl(parameter);

        canUpdate = I.HaveEdit;
    }
    BindGrid();
}

All this works fine, it's simple, and bool is used as part of another method (called a gridview expression) to conditionally display the control in a row. This also works great.

However, I am at the testing stage, and I realized that everything is fine with normal operations, but after some time (significant, for example, half an hour or so) the buttons no longer appear (in other words, canUpdate is false).

Code to display:

protected bool ShowNewStamps(object date)
{
    //Returns to Bind Expression whether to display Timestamp Link
    if (date == null & canUpdate == true)
        return true;
    else
        return false;
}

, , , .

, , , , ?

+4
3

static , , . IIS.

, . static . , - ( ), reset .

ViewState Session.

: static , , .

+2

reset .

, IIS AppDomain .

+3

static variables do not reset, unless you recycle the application pool. The difference between a static and a non-stationary variable is that when you define a static variable, you can make sure that it will exist during the life of the application, because they store the name of the high-frequency heap that is not under the control of the GC. but in the case of non-static variables, the GC controls their existence.

0
source

All Articles