Mandar Shinde

Mandar Shinde

  • NA
  • 423
  • 114.7k

Regarding HttpContext.Current.Session

Mar 20 2019 6:11 AM
Dear All,
I was developing simple login component using Anular 5 and  ASP .Net MVC 5 with API Controller.
While creating that functionality I am facing one problem i.e. I am not able to get value of HttpContext.Session object in another component.
Here is my ApiController Code :-
 
  1. public class LoginController : ApiController  
  2.     {  
  3.         private ILoginRepository _loginRepository;  
  4.         public LoginController()  
  5.         {  
  6.             _loginRepository = UnityFactory.ResolveObject();  
  7.         }  
  8.   
  9.         public HttpResponseMessage Post(string userName,string password)  
  10.         {  
  11.             string response = _loginRepository.Post(userName, password).ToString();  
  12.             if (response.Contains("302"))  
  13.             {  
  14.                 HttpContext.Current.Session.Add("UserName", userName);  
  15.                 string data = HttpContext.Current.Session["UserName"].ToString();  
  16.             }  
  17.   
  18.             return Request.CreateResponse(_loginRepository.Post(userName,password));  
  19.         }  
  20.     }  
Please help me in how to send session from ApiController To Angular 5 and vice versa.
Or you can suggest me another option to Session which will be accepted. 
Thanking You In Advance. 

Answers (3)