日期:2014-05-18  浏览次数:20416 次

类库中使用session问题。
public UserModel chkLogin(string sUserName, string sPassword)
  {
  UserModel um = new UserModel();
  um = dal.uLogin(sUserName, sPassword);
  if (um != null)
  {
  Session["user"] = um; // 此句出错:未将对象引用设置到对象的实例
  return um;
  }
  else
  {
  return null;
  }
  }

如何解决,谢谢。

------解决方案--------------------
HttpContext.Current.Session
------解决方案--------------------
类文件中没有继承System.Web.UI.Page 

所以在用response,request,session,cookie等对象时都写成HttpContext.Current.response这种形式
------解决方案--------------------
探讨

HttpContext.Current.Session

------解决方案--------------------
先引用System.Web,然后用HttpContext.Current.Session