我要在页面里判断session是否过期,如果在每个页面都加代码,很麻烦,我每个页面里都产生一个公共类的实例,我想在该类的构造函数中进行判断,以前问过别人在公共类里使用Response的方法,我想Session也一样,于是构造函数代码如下:
public DBAccess()
{
Session = HttpContext.Current.Session;
Response = HttpContext.Current.Response;
if(Session["UserRole"] == null)
{
WriteMessage("您已掉线,请重新登陆!",false,false);
WriteJavaScript("top.location.href='../Common/index.aspx';");
Response.End();
}
}
结果在执行的时候出现“未将对象设置到实例”的经典错误,请问高手我该怎么办?

解决方案 »

  1.   

    有什么问题可以去www.zhihuigu.com上去问,那有很多一流大虾.......高手如云..专门给人解决问题有问必答.....各位有时间都可以去看看!!!!!!!!!!!!!!!
      

  2.   

    Session = HttpContext.Current.Session;
    Response = HttpContext.Current.Response;
    感觉有问题(变量名实关键字)
    直接if(HttpContext.Current.Session["UserRole"] == null)试试
      

  3.   

    System.Web.HttpContext.Current.Session["UserRole"]
      

  4.   

    Session 是关键字换一个试试
      

  5.   

    对的,直接用System.Web.HttpContext.Current.Session["key"]我刚用过
      

  6.   

    System.Web.HttpContext.Current.Session[]
      

  7.   

    把session当作参数传进去不就行了!
      

  8.   

    System.Web.HttpContext.Current.Session["key"]
     这样就好了~!
      

  9.   

    System.Web.HttpContext.Current.Session[""]
      

  10.   

    System.Web.HttpContext.Current.Session在做控件的时候好象也可以
    page.session