2

So in my MVC App I require the user to login, handled by the AccountController,

And after successful login I save some extra properties to the session like so

Member member = dbContextRead.Members.Include(m => m.Location).SingleOrDefault(e => e.AspNetUserId == user.Id);
System.Web.HttpContext.Current.Session["member"] = member;
System.Web.HttpContext.Current.Session["location"] = member.Location;

But when I try to access the session in another controller and fetch the values it returns null.

var member = (System.Web.HttpContext.Current.Session["member"] as Member) ?? dbContext.Members.Single(m => m.AspNetUserId == user.Id);

Also a good thing to add, if I check the Session Id in the 2 different locations, they return a different session id and a different instance.

Why is that? Am I missing something, should this be setup somewhere?

Izzy
  • 6,740
  • 7
  • 40
  • 84
Andrei dela Cruz
  • 628
  • 4
  • 11

0 Answers0