如何知道会话是否已设置
在PHP我曾经使用过
session_start(); if(isset(SESSION["user"])) { //session is set } els{ // there is no session }
但我是否在asp.net中这样做? 我的意思是。 什么代码可以告诉会话设置与否
例如:asp.net c#
//login.aspx SESSION["USER"]; //user_profile.aspx if(SESSION["USER"])// how do i validate that?? { }
SESSION["USER"]; //this should throw an error since it's not setting a value and not a method.
您可以像这样测试会话值:
if (Session["USER"] != null) { //do something interesting }
如果你想检查一个会话变量的存在,这将是好的:
if(Session["USER"] != null) { //If you get here a session variable "USER" exists... }
虽然可以在asp.net应用程序中禁用会话状态 ,但很少见到这一点。
从php端,cince issetfunction
确定变量是否已设置且不为NULL。
只需检查此会话是否为null
:
if(Session["USER"] != null) { // Do something }