【发布时间】:2016-03-05 21:02:22
【问题描述】:
我无法确定登录应用程序后会话何时首次可用以及用户身份验证。 我的目标是在用户登录到应用程序后将有关用户的一些数据保存到会话中(登录后立即,在其他任何事情发生之前),以便我以后可以使用它。 我在 VS2015 中使用默认的 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
}
你能帮帮我吗?
【问题讨论】:
-
为什么需要在会话中保存值?
-
好吧,我想保存一些用户特定的数据,以便在应用程序中进一步使用。会话看起来像是保存它的好地方:-)
标签: asp.net-mvc session login asp.net-mvc-5