For example, I Have the following static class:
public static class f
{
public static bool IS_GUEST = (HttpContext.Current.Session["uid"] == null);
public static bool IS_ADMIN = (HttpContext.Current.Session["admin"] != null);
//...
Now If i check whether the user is Guest or not using IS_GUEST i always get true even if the user is not a guest (session “uid” does exist). And for IS_ADMIN i get always false, no matter what. The sessions are created before i call IS_GUEST and IS_ADMIN, and if I check it manually (HttpContext.Currest.Session[something]) it works fine.
So what’s the problem here?
Static initializers are run before any method in your code. So quite likely the HttpContext.Current.Session has not been initialized when your fields are initialized. Change them to properties and everything ought to work as expected.