2

在用户创建会员资格(创建帐户)后,登录后但在下一个 httprequest 之前,我正在尝试为用户配置文件分配一些值

虽然,我尝试在分配配置文件值之前登录/验证用户,但直到下一个 httprequest 用户才会被验证。

这就是我的代码的样子:

    [HttpPost]
    public ActionResult Register(RegisterModel model)
    {
        if (ModelState.IsValid)
        {
            // Attempt to register the user
            MembershipCreateStatus createStatus = UserService.CreateUser(model.Email, model.Password);

            if (createStatus == MembershipCreateStatus.Success)
            {
                //Adding role
                UserService.AddDefaultRole(model.Email);

                FormsService.SignIn(model.Email, false); //Inside: FormsAuthentication.SetAuthCookie(email, createPersistentCookie);


                HttpContext.Current.Profile["FistName"] = firstName; //WON'T WORK - USER ISN'T AUTHENTICATED YET
                HttpContext.Current.Profile["LastName"] = lastName; // WON'T WORK

                return RedirectToAction("List", new { area = "Requests", controller = "Requests" }); //User will only be authenticated after this this redirection
             }

我正在考虑启用匿名用户,分配配置文件值,然后在下一个 httprequest 之后(当用户通过身份验证时)将此数据传递给已通过身份验证的用户。

有没有办法做到这一点?如果是这样,是否有任何教程可以做到这一点?如果没有,我应该如何解决这个问题?

4

1 回答 1

0

为什么不将这些值放在 cookie 中,在帐户创建时重定向到读取 cookie 并更新配置文件的操作,然后再次重定向到您希望注册人最终到达的任何位置?

于 2011-09-10T20:20:48.163 回答