C# Cannot check Session exists?

前端 未结 8 2006
遥遥无期
遥遥无期 2020-12-14 20:26

I get an error when I do the following:

if(Session[\"value\"] != null)
{
   // code
}

The error i get is this:

Object reference not

相关标签:
8条回答
  • 2020-12-14 20:59

    You also can use:

    if (Session == null || String.IsNullOrEmpty((string)Session["session_object"])){
       // Do something
    }
    
    0 讨论(0)
  • 2020-12-14 21:05

    I solve by this way:

    if (Session.Count > 0 && Session["mySessionVariable"].ToString() != null)
    {
    
    }
    
    0 讨论(0)
提交回复
热议问题