0

I just started learning asp.net and c#.

Let say I have a session like this:

Session.Add("username","me");

At a later section, I wanna learn whether that session has been defined. How can i do that ? I tried to do this :

if(Session["username"]){
   // some code
}

but of course it didn't work.

keenthinker
  • 7,645
  • 2
  • 35
  • 45
m.a.a.
  • 137
  • 1
  • 9
  • What kind of error message do you get? What kind of type has the content that you put into the session? Does `if` supports this kind of type? – keenthinker Aug 20 '16 at 13:18

1 Answers1

0

Try this code

        if (Session["username"] != null)
        {

        }
Anirudha Gupta
  • 9,073
  • 9
  • 54
  • 79