I have been trying to consume an Api that I created in .NET MVC
from the Web Layer of my app using angularjs's $http.get()
method. I am making bunch of $http.get()
invocations to call API endpoints. The problem comes when I try to access session data that is being set on the 1st $http.get()
call in the App tier of my application. when I try to access the Session data using another $http.get()
, the session is not available.
In the Angular Controller I am doing this:
$http.get(http://localhost:50033/api/HomeController/SetSessionData)
.then($http.get(http://localhost:50033/api/HomeController/GetSessionData)
.then(//Do Something with sessiondata))
In the Home Controller I am doing:
[HttpGet]
public IHttpActionResult SetSession()
{
HttpContext.Current.Session["Data"]=//Some Data being fetched fromDB;
return //Data from DB as Json
}
[HttpGet]
public IHttpActionResult GetSession()
{
if( HttpContext.Current.Session["Data"]!=null)//I am getting Null here even though I set it in the SetSession call.
{
return Json(HttpContext.Current.Session["Data"]);
}
}
`