==============================  aspx 页面代码  ==================
<%@ Page language="c#" AutoEventWireup="false" EnableViewState="false" Inherits="AppName.App_Data.Default3" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>
==============================  cs页面代码  ==================
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.SessionState;
namespace AppName.App_Data
{
    public class Default3 : System.Web.UI.Page, IRequiresSessionState
    {
        public Default3()
        {
            object IsLogined = System.Web.HttpContext.Current.Session["IsLogined"];
            if (IsLogined != null){}
            else{}
        }
    }
}
运行提示:未将对象引用设置到对象的实例。 System.Web.HttpContext.Current.Session  = null  不知道怎么回事,大家帮忙看看!!

解决方案 »

  1.   

    System.Web.HttpContext.Current.Session = null ??System.Web.HttpContext.Current.Session["IsLogined"]=null;
      

  2.   

    你有没有给System.Web.HttpContext.Current.Session["IsLogined"];赋值啊。
      

  3.   

    System.Web.HttpContext.Current.Session == null并不是 System.Web.HttpContext.Current.Session["IsLogined"]=null;
      

  4.   

     object IsLogined = System.Web.HttpContext.Current.Session["IsLogined"];在这里就错了,按道理这里不会错了,就算 IsLogined 没值 返回的也是 null
      

  5.   

    object IsLogined = System.Web.HttpContext.Current.Session["IsLogined"];在这里就错了,按道理这里不会错了,就算 IsLogined 没值 返回的也是 null, 就算没有 isLogined这个 session 返回的也是 null  
      

  6.   

    if(System.Web.HttpContext.Current.Session != null)
    {
        //你的语句。原因是有可能此对像没有被创建。
    }
      

  7.   

    英雄,你好好看一看,你的public Default3()
      {
      object IsLogined = System.Web.HttpContext.Current.Session["IsLogined"];
      if (IsLogined != null){}
      else{}
      }这段代码,你在页面类的构造函数中访问session,能访问到才怪,不知道你学没学过asp.net的生命周期,在所有生命周期之前,第一个要执行的方法绝对是类的构造函数啊,这时候所有的数据都还没有回填,怎么可能会有值。
    这就是为什么总是在page_load中去访问session了,你的代码是从哪里看到的????
      

  8.   

    System.Web.HttpContext.Current.Session["IsLogined"]
    这个东西别人应该在什么地方赋值过了,你只Copy了别人的部分代码,所以这个东西一直为空。
      

  9.   


    protected string IsLogined 
    {
      get
    {
    return Session["IsLogined"] == null ? 
    String.Empty : 
    Session["IsLogined"].ToString();
     }
     }用到之前做一下非空判断
      

  10.   


    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Web.SessionState;
    namespace AppName.App_Data
    {
      public class Default3 : System.Web.UI.Page, IRequiresSessionState
      {
      public Default3()
      {
        if (null != System.Web.HttpContext.Current.Session["IsLogined"]){
    object IsLogined = System.Web.HttpContext.Current.Session["IsLogined"];
    //这里你可以去作你想要的操作或处理..
    }
      else{}
      }
      }
    }
      

  11.   

    不知道是不是为null的时候不可以赋值给其他object呢....
    我猜测的.哈哈