将配置文件数据从匿名用户传递给登录用户

时间:2011-08-27 17:52:01

标签: .net asp.net-mvc asp.net-profiles

我尝试在用户创建成员身份(创建帐户)后,在登录后但在下一个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之后(当用户通过身份验证时)将此数据传递给已经过身份验证的用户。

有没有这样做? 如果是这样,是否有任何教程可以做到这一点? 如果没有,我该如何处理这个问题?

1 个答案:

答案 0 :(得分:0)

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

相关问题