如何知道会话是否已设置

Mis*_*ers 13 c# asp.net

在PHP我曾经使用过

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

但我在asp.net中这样做吗?我的意思是.什么代码可以告诉会话设置与否

例如:asp.net c#

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

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

}
Run Code Online (Sandbox Code Playgroud)

jTC*_*jTC 22

SESSION["USER"]; //this should throw an error since it's not setting a value and not a method.
Run Code Online (Sandbox Code Playgroud)

您可以像这样测试会话值:

if (Session["USER"] != null)
{
    //do something interesting
}
Run Code Online (Sandbox Code Playgroud)