结帐流程工作流程,遇到重定向问题

时间:2020-11-29 11:25:40

My checkout process has the following workflow:

我的结帐流程具有以下工作流程:

  1. checkout page
  2. 结帐页面
  3. shipping address
  4. 邮寄地址
  5. edit shipping address(add/edit)
  6. 编辑送货地址(添加/编辑)
  7. delivery method
  8. 运输方式
  9. payment
  10. 付款
  11. place order
  12. 下订单

Each of the above steps has its own action in the same controller.

上述每个步骤在同一个控制器中都有自己的动作。

Now the issue is, if the person gets to #5, and wants to edit the address, they go back to #3. But when they hit submit, they go to the next step, #4, but they should go straight back to #5.

现在的问题是,如果这个人到达#5,并想要编辑地址,他们会回到#3。但当他们点击提交时,他们会进入下一步#4,但他们应该直接回到#5。

I know I can pass information via a query string/form and tell #3 to check for the presence of that key, if its there, then redirect to #5.

我知道我可以通过查询字符串/表单传递信息,并告诉#3检查是否存在该密钥,如果存在,则重定向到#5。

Are there any proven, best-practice techniques to manage a workflow like this in asp.net-mvc (or in general)?

是否有任何经过验证的最佳实践技术来管理asp.net-mvc(或一般)中的此类工作流程?

2 个解决方案

#1


1  

Usually I will set up a session to store the state and data of the user, and from determine which step to go on to next. Hence the controller upon being invoked could run some logic to determine which state the user is at, and then invoke the rendering code to output the form associated with the user's current state.

通常我会设置一个会话来存储用户的状态和数据,并确定继续下一步的步骤。因此,被调用的控制器可以运行一些逻辑来确定用户所处的状态,然后调用呈现代码以输出与用户的当前状态相关联的表单。

IMHO, this streamlines the process as you don't delegate the 'what's my next state' checking to the forms level, but to a centralised location, which makes it easy to add in new business logic down the road.

恕我直言,这简化了流程,因为您没有将“我的下一个状态”检查委托给表单级别,而是集中到一个集中位置,这样可以轻松地在未来添加新的业务逻辑。

Hope this helps!

希望这可以帮助!

(You could replace session with invisible form fields, query strings and etc.)

(您可以用不可见的表单字段,查询字符串等替换会话)

#2


0  

If you really do "hate sessions" as you say, there is potentially another option, which is to pass a querystring for all "backward" operations defining where to go next.

如果你真的如你所说的那样“讨厌会话”,那么可能还有另一种选择,即为所有“向后”操作传递一个查询字符串,定义下一步的去向。

This is how most Login pages work -- if you are not authorized to view a page, it will redirect to the Login page with a redirectUrl querystring parameter set. Then on successful login you'll be redirected to the page you originally came from.

这就是大多数登录页面的工作方式 - 如果您无权查看页面,它将使用redirectUrl查询字符串参数集重定向到“登录”页面。然后,在成功登录后,您将被重定向到您最初来自的页面。

And just to simplify your code a little you could overload the RedirectToAction() method on your controller such that it redirects to the given action UNLESS there's a that special querystring, in which case it redirects there.

只是为了简化你的代码,你可以重载控制器上的RedirectToAction()方法,使它重定向到给定的操作,除非有一个特殊的查询字符串,在这种情况下它会重定向到那里。

edit: I know that you mentioned this as a possibility, but I posted it anyway because: 1) there's nothing wrong with it (especially if you "hate sessions"), and 2) you mentioned having your Action check for the presence of the key, which I think could be better written as I described (using an overload -- DRY)

编辑:我知道你提到这是一种可能性,但我发布它仍然是因为:1)它没有任何问题(特别是如果你“讨厌会话”),2)你提到你的行动检查是否存在键,我认为可以更好地编写,如我所描述的(使用重载 - 干)

#1


1  

Usually I will set up a session to store the state and data of the user, and from determine which step to go on to next. Hence the controller upon being invoked could run some logic to determine which state the user is at, and then invoke the rendering code to output the form associated with the user's current state.

通常我会设置一个会话来存储用户的状态和数据,并确定继续下一步的步骤。因此,被调用的控制器可以运行一些逻辑来确定用户所处的状态,然后调用呈现代码以输出与用户的当前状态相关联的表单。

IMHO, this streamlines the process as you don't delegate the 'what's my next state' checking to the forms level, but to a centralised location, which makes it easy to add in new business logic down the road.

恕我直言,这简化了流程,因为您没有将“我的下一个状态”检查委托给表单级别,而是集中到一个集中位置,这样可以轻松地在未来添加新的业务逻辑。

Hope this helps!

希望这可以帮助!

(You could replace session with invisible form fields, query strings and etc.)

(您可以用不可见的表单字段,查询字符串等替换会话)

#2


0  

If you really do "hate sessions" as you say, there is potentially another option, which is to pass a querystring for all "backward" operations defining where to go next.

如果你真的如你所说的那样“讨厌会话”,那么可能还有另一种选择,即为所有“向后”操作传递一个查询字符串,定义下一步的去向。

This is how most Login pages work -- if you are not authorized to view a page, it will redirect to the Login page with a redirectUrl querystring parameter set. Then on successful login you'll be redirected to the page you originally came from.

这就是大多数登录页面的工作方式 - 如果您无权查看页面,它将使用redirectUrl查询字符串参数集重定向到“登录”页面。然后,在成功登录后,您将被重定向到您最初来自的页面。

And just to simplify your code a little you could overload the RedirectToAction() method on your controller such that it redirects to the given action UNLESS there's a that special querystring, in which case it redirects there.

只是为了简化你的代码,你可以重载控制器上的RedirectToAction()方法,使它重定向到给定的操作,除非有一个特殊的查询字符串,在这种情况下它会重定向到那里。

edit: I know that you mentioned this as a possibility, but I posted it anyway because: 1) there's nothing wrong with it (especially if you "hate sessions"), and 2) you mentioned having your Action check for the presence of the key, which I think could be better written as I described (using an overload -- DRY)

编辑:我知道你提到这是一种可能性,但我发布它仍然是因为:1)它没有任何问题(特别是如果你“讨厌会话”),2)你提到你的行动检查是否存在键,我认为可以更好地编写,如我所描述的(使用重载 - 干)