在ASP.NET C中调用Web服务时,Session为null

mhe*_*abi 15 c# asp.net session web-services

我有一个Login类,它有一个函数:isCorrect(),它将用户名和密码作为两个属性和一个asp.net WebService来允许使用AJAX.

LoginService.cs

public Login CorrectLogin(string username, string password) 
{   
   Login thisLogin = Login.isCorrect(username, password);
   int thisLoggedinUserID = thisLogin.LoggedinUserID;

   if (thisLoggedinUserID != 0)
   {
      Session["loggedinUser"] = thisLoggedinUserID;
   }

   return thisLogin;
}
Run Code Online (Sandbox Code Playgroud)

当我想设置Session["loggedinUser"] = thisLoggedinUserID此错误的值时:

Object reference not set to an instance of an object.

我无法理解什么是解决方案.

Dom*_*icz 31

默认情况下,Web服务没有Session.将属性添加到WebMethod ..

 [WebMethod(EnableSession=true)]
 public Login CurrentLogin .....
Run Code Online (Sandbox Code Playgroud)