session中未将对象实例化解决方案
session中未将对象实例化
调试报未将对象实例化
这是部分代码
string name = HttpContext.Current.Request["name"].ToString();
string pwd = HttpContext.Current.Request["pwd"].ToString();
DataTable dt = bll.getUse();
bool post = false;
string names = null;
int id = 0;
foreach (DataRow row in dt.Rows)
{
if (row["username"].ToString() == name && row["pwd"].ToString() == pwd)
{
names = row["username"].ToString();
id = int.Parse(row["id"].ToString());
post = true;
}
}
if (post == true)
{
HttpContext.Current.Session["names"] = names;
HttpContext.Current.Session["id"] = id;
HttpContext.Current.Response.Write("ok");
}
else
{
HttpContext.Current.Response.Write("error");
}
应该如何解决,跪求啊!!!
------解决思路----------------------
HttpContext.Current.Session
HttpContext.Current
HttpContext
其中一个没有初始化,或者都没有初始化,是null
------解决思路----------------------
需要引用接口IReadOnlySessionState
------解决思路----------------------
你的页面不是继承自System.Web.UI.Page吗
System.Web.UI.Page里已经引用了System.Web.SessionState了
调试报未将对象实例化
这是部分代码
string name = HttpContext.Current.Request["name"].ToString();
string pwd = HttpContext.Current.Request["pwd"].ToString();
DataTable dt = bll.getUse();
bool post = false;
string names = null;
int id = 0;
foreach (DataRow row in dt.Rows)
{
if (row["username"].ToString() == name && row["pwd"].ToString() == pwd)
{
names = row["username"].ToString();
id = int.Parse(row["id"].ToString());
post = true;
}
}
if (post == true)
{
HttpContext.Current.Session["names"] = names;
HttpContext.Current.Session["id"] = id;
HttpContext.Current.Response.Write("ok");
}
else
{
HttpContext.Current.Response.Write("error");
}
应该如何解决,跪求啊!!!
------解决思路----------------------
HttpContext.Current.Session
HttpContext.Current
HttpContext
其中一个没有初始化,或者都没有初始化,是null
------解决思路----------------------
需要引用接口IReadOnlySessionState
------解决思路----------------------
你的页面不是继承自System.Web.UI.Page吗
System.Web.UI.Page里已经引用了System.Web.SessionState了