Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know if a session has been set [duplicate]

Tags:

c#

asp.net

In php i used to use

session_start();
if(isset(SESSION["user"]))
{
   //session is set
}
els{
    // there is no session 
}

but do i do that in asp.net? I mean. What code can tells wheather a session is set or not

ex: asp.net c#

//login.aspx
SESSION["USER"];

//user_profile.aspx
if(SESSION["USER"])// how do i validate that??
{

}
like image 293
Misters Avatar asked Feb 25 '13 21:02

Misters


People also ask

How do you check if session is set or not?

You can check whether a variable has been set in a user's session using the function isset(), as you would a normal variable. Because the $_SESSION superglobal is only initialised once session_start() has been called, you need to call session_start() before using isset() on a session variable. For example: <?

Which of the following is used to check if session variable is already set or not in php?

Make use of isset() function to check if session variable is already set or not.

How do you check session is set or not in codeigniter?

3 Answers. Show activity on this post. $this->session->set_userdata('some_name', 'some_value');

How check session is empty?

If you want to check whether sessions are available, you probably want to use the session_id() function: session_id() returns the session id for the current session or the empty string ("") if there is no current session (no current session id exists).


1 Answers

SESSION["USER"]; //this should throw an error since it's not setting a value and not a method.

You can test your session values like this:

if (Session["USER"] != null)
{
    //do something interesting
}
like image 129
jTC Avatar answered Oct 12 '22 03:10

jTC