0

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"]);
        }
    }

`

georgeawg
  • 48,608
  • 13
  • 72
  • 95
  • It looks like your JavaScript is malformed; was the Controller code copied from your actual source code, or did you type that here? If it was copied, then you're likely missing some "quote" marks and `function()` declarations, and I wouldn't be surprised if the JavaScript console is displaying errors. If you just typed it here, you might want to revise it to be closer to your actually code to make this easier for others to answer. – Sean Werkema Feb 28 '17 at 19:02
  • I think you are doing it wrong. See this http://stackoverflow.com/questions/11478244/asp-net-web-api-session-or-something – mbeso Feb 28 '17 at 19:03
  • **Eliminate any issues that aren't relevant to the problem.** If your question isn’t about a compiler error, ensure that there are no compile-time errors. – georgeawg Feb 28 '17 at 23:31

0 Answers0