2015-04-04 51 views
0

我有一个网站,由此用户来临时,寄存器,登记有三个部分如下三部分认证

  1. 1部分:用户选择用户名,进入的电子邮件,DOB。然后按提交并被引导到第2部分
  2. 第2部分:用户输入关于她/她自己的附加信息。新闻提交并被引导到第3部分
  3. 第3部分:用户可以选择上传图像。然后按提交

第3部分后,我认证用户并登录他们,我试图找出问题是当他们从第1部分到第3部分我需要保持跟踪它所以在第1部分之后,我会将值保存在数据库中,并为该用户返回一个UniqueId,并将其存储在会话中,并在第2部分和第3部分中引用它,过去会话中有几个问题,我试图想到一个具体的解决方案来使用,而不是会话。我尝试了谷歌搜索,但看看世界上其他人是否做了类似的事情,但没有运气,因此我决定在这里提出这个问题。

+2

您可以以cookie或隐藏窗体值的形式将值返回给用户。这样,用户的状态将由用户保存,而不是由Web服务器保存。当用户提交下一步的请求时,该请求会携带该ID。 (如果没有,服务器会再次启动用户。)除非绝对必要,否则我会避免在Web服务器会话中维护任何状态。让状态由页面或数据库来执行。 – David 2015-04-04 00:39:03

+0

@David似乎是一个好主意,我更倾向于一个cookie,但我认为隐藏的领域可能是一个更好的解决方案,我可以将它从控制器1传递到控制器3。 – 2015-04-04 00:41:24

+0

Cookie可以完成同样的事情。这一切都归结于您期望的用户体验。如果用户需要在一个会话中浏览整个流程,那么将其作为表单值保留在页面上就可以了。如果用户可以放弃会话,关闭他们的浏览器,稍后再回来返回,那么cookie会更合适。这似乎并不是仅仅在网站上注册的可能用例。 – David 2015-04-04 00:42:57

回答

0

如果您希望它们能够关闭浏览器并稍后继续,您将希望使用cookie来存储用户的进度。如果不知道你的完整项目,很难提供一个确切的解决方案,但这肯定会对你有所帮助。

public ActionResult Signup() 
    { 
     //The cookie could be stored in the format: partnumber_databaseid 
     //An example cookie would look like 1_24 
     if (request.Cookies["SingupProgress"] != null) 
     { 
      var part = request.Cookies["SignupProgress"].ToString().Split('_')[0]; 
      var id = request.Cookies["SignupProgress"].ToString().Split('_')[1]; 

      //Eg if the cookie stored number "1" as part, the returned view would be "Part2" 
      //Return the stored part number plus one, as the part number will represent which part they have already completed 
      string ViewName = "Part" + part + 1; 

      return View(ViewName); 
     } 
     else 
     { 
      //If the cookie doesn't exist, that means the user has not made any sign up progress 
      //Direct them to the first signup part 
      return View("Part1"); 
     } 

    } 

    public ActionResult Part2() 
    { 
     //Direct the user to this action once they have clicked next on the Part 1 view 

     //Create the class to store the progress data. 
     //You also need this to extract the Unique ID for the cookie 
     ProgressClass Progress = new ProgressClass(/*Your data*/); 

     //Store the progress into the database 
     db.StoreProgressData(); 
     db.Save(); 

     //Get the unique ID that you just saved into the database 

     int Id = Progress.Id; 

     HttpCookie ProgressCookie = new HttpCookie("SignupProgress", Id + "_2"); 
    } 

    //Once they reach part 3 your final link can direct them to a register action, which creates the account and saves it to a database