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??
{
}
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: <?
Make use of isset() function to check if session variable is already set or not.
3 Answers. Show activity on this post. $this->session->set_userdata('some_name', 'some_value');
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).
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With