【发布时间】:2012-10-09 22:23:54
【问题描述】:
我正在尝试确定 Session 变量是否存在,但出现错误:
System.NullReferenceException:对象引用未设置为对象的实例。
代码:
// Check if the "company_path" exists in the Session context
if (System.Web.HttpContext.Current.Session["company_path"].ToString() != null)
{
// Session exists, set it
company_path = System.Web.HttpContext.Current.Session["company_path"].ToString();
}
else
{
// Session doesn't exist, set it to the default
company_path = "/reflex/SMD";
}
那是因为Session名称“company_path”不存在,但我检测不到!
【问题讨论】:
标签: c# asp.net session session-variables nullreferenceexception