I cannot figure out when after login to an app is the session first time available along with user authentication. My goal is after a user logs in to the app to save some data about the user into session (right away after the login, before anything else happens), so I can use it later. I use the default MVC 5 template with VS2015. My login looks like
var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
switch (result)
{
case SignInStatus.Success:
return RedirectToLocal(returnUrl); //I jump here
case SignInStatus.LockedOut:
return View("Lockout");
case SignInStatus.RequiresVerification:
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
case SignInStatus.Failure:
default:
ModelState.AddModelError("", "Invalid login attempt.");
return View(model);
}
private ActionResult RedirectToLocal(string returnUrl)
{
//here I would like to save some stuff into the session, the session is available here but the user is not authenticated yet
if (Url.IsLocalUrl(returnUrl))
{
return Redirect(returnUrl);
}
return RedirectToAction("Index", "Course");
}
Ok, next I tried global.asax:
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
//and of course here I have authenticated user but the session is null
}
Can you help me out, please?