存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 "";
}
出现的问题:未将对象设置到对象实例~
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 "";
}
出现的问题:未将对象设置到对象实例~
{
return HttpUtility.UrlDecode(HttpContext.Current.Session["Name"].ToString());
}
else
{
return "";
}HttpContext.Current.Session["Name"]也要做非空判断。再操作它
比如:
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() : "";
这部就非空了 为什么呢?