I’m having users login to my site using Facebook. They are sent away from my site to Facebook and then redirected back after they have given the site permission. The problem I’m facing is accessing the Session variables I set before they left the site. When the user returns to the site an entirely new Session is created. The strange thing is if the user navigates the site, some pages the original session will be accessible, and sometimes the newly created session.
I’ve tried creating cookies:
Response.Cookies[“user”][“LoggedIn”] = “true”;
As long as the user hasn’t left the site I’m able to access those cookies fine, but as soon as soon as they leave and come back I don’t seem to be able to access those either. So my question is what is the best way to persist data from before before a user is sent away from the site to when then are redirected back?
AccountController:
public void Login()
{
Session["BeforeLogin"] = "foo";
redirect(FacebookUrl);
}
//Where Facebook redirects the user back to
public ActionResult OAuth(string code, string state)
{
if (LoginSuccessful)
{
Session["LoggedIn"] = true;
}
return View();
}
HomeController:
public HomeController()
{
setLoggedInSession();
}
public void setLoggedInSession()
{
//This is where I'm having the inconsistency
string foo = Session["BeforeLogin"];
ViewData["LoggedIn"] = Session["LoggedIn"];
//It'll either be BeforeLogin is null and LoggedIn is true
//or BeforeLogin will be "foo" and LoggedIn will be null
}
EDIT:
Some new information about this issue. Doing some testing I’ve found that the Session seems to work fine when I’m only using a single instance. When I do high availability though (running 5 instances) is when I start experiencing the issues. Most noticeably in IE. My hypothesis is that when you’re redirected back to the site from Facebook you’re getting a different instance than you left and it creates a new session before it manages retrieves the original one.
AppFabric Caching:
“Consistent development model across both Windows Azure AppFabric and Windows Server AppFabric.
Secured access and authorization provided by the Access Control service.”
It’s non-resident to any one instance.