Checking session if empty or not

后端 未结 6 829
萌比男神i
萌比男神i 2020-12-28 13:39

I want to check that session is null or empty i.e. some thing like this:

if(Session[\"emp_num\"] != null)
{

   if (!string.IsNullOrEmpty(Session[\"emp_num\"         


        
6条回答
  •  北海茫月
    2020-12-28 14:26

    Check if the session is empty or not in C# MVC Version Lower than 5.

    if (!string.IsNullOrEmpty(Session["emp_num"] as string))
    {
        //cast it and use it
        //business logic
    }
    

    Check if the session is empty or not in C# MVC Version Above 5.

    if(Session["emp_num"] != null)
    {
        //cast it and use it
        //business logic
    }
    

提交回复
热议问题