在基类里边判断session的时候出错的处理方法

当我在pagebase类中判断session时,出现了:“  未将对象引用设置到对象的实例”;

         if (System.Web.HttpContext.Current.Session["username"] != null)  

百度一下 原来

    “没有相应的用户访问所以没有current ” 所以需要 判断一下 if (System.Web.HttpContext.Current!= null&& System.Web.HttpContext.Current.Session)   

这样才不至于导致这样的错误!

原文地址:https://www.cnblogs.com/gogood/p/4316000.html