我是 MVC 的新手,所以这个问题可能是微不足道的。在我的登录操作中,我执行以下操作:
public ActionResult LogOn(UserModel userModel, string returnUrl)
    {
        ActionResult retvalue = null;
        UserProfile user = MyDatabaseAccess.Instance.GetAuthenticatedUser(userModel.EmailAddress, userModel.Password);
        if (user != null)
        {
            FormsAuthentication.SetAuthCookie(userModel.EmailAddress, userModel.RememberMe);
            Session["LoggedOnUser"] = user;
            if (Url.IsLocalUrl(returnUrl))
            {
                retvalue = Redirect(returnUrl);
            }
            else
            {
                retvalue = RedirectToAction("Home", "Home");
            }
        }
        else
        {
            retvalue = RedirectToAction("LogOn", "Account");
        }
        return retvalue;
    }
此时,我的会话具有完整的 UserProfile 对象,并且我通过网站使用它,到目前为止一切正常。
下次用户访问该网站时,该用户已经通过身份验证(rememberme 设置为 true),并且 User.Identity.Name 具有之前通过身份验证的用户的电子邮件地址,这是正确的。问题是我想将 UserProfile 加载到会话中,就像在 LogOn 操作中一样。我想要一个我这样做的地方,而不是在每个 [授权] 行动中。
有没有这样的方法?