我无法弄清楚什么时候登录到应用后会话第一次可以与用户认证一起使用。 我的目标是在用户登录到应用程序后,将有关用户的一些数据保存到会话中(在登录之后,在发生其他任何事情之前),以便稍后使用它。 我在VS2015中使用默认的MVC 5模板。 我的登录看起来像认证后的MVC 5会话
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");
}
确定,下一步我想的Global.asax:
protected void Application_AuthenticateRequest(object sender, EventArgs e)
{
//and of course here I have authenticated user but the session is null
}
你能帮助我,好吗?
为什么你需要在会话中保存值? – Hadee
那么,我想保存一些用户特定的数据,以便在应用程序中进一步使用。该会议看起来像一个很好的地方保存在那里:-) –