存SessionHttpContext.Current.Session["Grade"] = System.Web.HttpUtility.UrlEncode(ds.Tables[0].Rows[0]["Member_grade"].ToString());
HttpContext.Current.Session["Guid"] = ds.Tables[0].Rows[0]["mem_Guid"].ToString();
HttpContext.Current.Session["Name"] = HttpUtility.UrlEncode(ds.Tables[0].Rows[0]["mem_UserName"].ToString());
当我登陆的时候想判断是否为空if (HttpContext.Current.Session["Guid"] != null)
{
     return HttpUtility.UrlDecode(HttpContext.Current.Session["Name"].ToString());
}
else
{
     return "";
}
出现的问题:未将对象设置到对象实例~

解决方案 »

  1.   

    if (HttpContext.Current.Session["Guid"] != null)
    {
         return HttpUtility.UrlDecode(HttpContext.Current.Session["Name"].ToString());
    }
    else
    {
         return "";
    }HttpContext.Current.Session["Name"]也要做非空判断。再操作它
      

  2.   


    比如:
    HttpContext.Current.Session["Grade"] = System.Web.HttpUtility.UrlEncode(ds.Tables[0].Rows[0]["Member_grade"].ToString());最好也做非空判断。。HttpContext.Current.Session["Grade"] = !string.IsNullOrEmpty(System.Web.HttpUtility.UrlEncode(ds.Tables[0].Rows[0]["Member_grade"]) : ystem.Web.HttpUtility.UrlEncode(ds.Tables[0].Rows[0]["Member_grade"].ToString() : "";
      

  3.   

    if (HttpContext.Current.Session["Guid"] != null)
    这部就非空了 为什么呢?
      

  4.   

    你外面判断的Session["Guid"] 里面用的Session["Name"]
      

  5.   

    我在cs类中调用session["Name"].ToStrong();  有值在BLL类中的一个类调用HttpContext.Current.Session["Guid"]为什么是空呢??