我自己定义了个类PageSession,继承System.Web.UI.Page构造方法里面判断HttpContext.Current.Session["Islogin"]是否为空 if (HttpContext.Current.Session["Islogin"]==null)//未将对象引用设置到对象的实例。
{
HttpContext.Current.Response.Write("session Is Null");
}
else
{
HttpContext.Current.Response.Write("session Is NotNull");
}
以后需要session判断的页都继承此类PageSession但运行的时候一直报错。未将对象引用设置到对象的实例。还有想问问这两者的区别,谢谢
{
HttpContext.Current.Response.Write("session Is Null");
}
else
{
HttpContext.Current.Response.Write("session Is NotNull");
}
以后需要session判断的页都继承此类PageSession但运行的时候一直报错。未将对象引用设置到对象的实例。还有想问问这两者的区别,谢谢
这个通常用在单独的类里
Page.Session一般是页面的后置类里用.
那HttpContext.Current.Session
和Page.Session相等吗?
{
public PageSession()
{
if (HttpContext.Current.Session["Islogin"] == null)//为什么这里一直报错未将对象引用设置到对象的实例。
{
HttpContext.Current.Response.Write("session Is Null");
}
else
{
HttpContext.Current.Response.Write("session Is NotNull");
}
}
}
if (HttpContext.Current.Session["Islogin"] == null)
{
Response.Write("ddd");
}在page里这样不报错
System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;
string sid = Convert.ToString(System.Web.HttpContext.Current.Session["Employee_Code"]);//使用字符串转换
if (sid == null || sid == "")
{}
在自定义 HTTP 处理程序中实现 IRequiresSessionState 接口,以确定处理程序是否需要对会话状态值具有读写访问权
你从头查下程序。未将对像引用到实例可能是由于其它地方出问题导至的
在重写OnLoad事件中处理吧
{
base.OnLoad(e);
if (System.Web.HttpContext.Current.Session["Islogin"] == null)
{
HttpContext.Current.Response.Write("session Is Null");
}
else
{
HttpContext.Current.Response.Write("session Is NotNull");
}
}