C# Cannot check Session exists?

前端 未结 8 2019
遥遥无期
遥遥无期 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
    }
    

提交回复
热议问题