Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Session is null when calling a web service in ASP.NET C#

I have a Login Class which has a function: isCorrect() that takes username and password as two attributes And a asp.net WebService To allow using 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;
}

When I want to set value of Session["loggedinUser"] = thisLoggedinUserID this error accrues:

Object reference not set to an instance of an object.

I can't understand what is solution.

like image 844
mhesabi Avatar asked Mar 22 '12 20:03

mhesabi


1 Answers

Web services don't have Session by default. Add an attribute to the WebMethod..

 [WebMethod(EnableSession=true)]
 public Login CurrentLogin .....
like image 164
Dominic Zukiewicz Avatar answered Oct 06 '22 19:10

Dominic Zukiewicz