具有 Post/Redirect/Get 功能的 ASP.NET 向导

发布于 2024-10-05 16:18:07 字数 668 浏览 5 评论 0原文

我正在习惯 Post/Redirect/Get 模式,我发现它是一个非常好的过程,而且它似乎也让我更多地思考页面结构,而不是过于频繁地依赖 ASP.Net 事件。

我目前正在为站点编写向导功能,虽然没有使用 ASP.NET Wizard 控件,但使用 MultiView 更手动地处理它。通常在过去,我预计典型的用户体验是 GET >发布>发布> POST 等向导的每个后续步骤。然而,我现在正在考虑使用更多的P/D/G方法,人们经常用他们的巫师这样做吗?

我当前的想法是,一旦用户完成某个步骤并选择继续,包含当前向导信息的会话对象将被保存回会话,然后将进行 GET 重定向返回向导页面。当向导页面加载时,将询问 Session 对象以确定向用户显示的正确步骤。

我可以看到这样做有两个很好的优点:

  1. 它具有 P/R/G 通常的好处,它消除了刷新问题,而且
  2. 用户可以导航离开向导并返回到它(如果他们的会话仍然处于活动状态),他们将直接进入正确的步骤。

人们认为这是一个更简洁的设计吗?有明显的缺点吗?我想我可能会变成一个更加愤世嫉俗的程序员,并且更少信任 ASP.Net 和回发生命周期,但这并不是说这种方法会导致更多的代码?如果我没有实现它,我就必须针对用户刷新或尝试导航到他们不应该执行的步骤写入所有检查。

I am getting used to the Post/Redirect/Get pattern, I find it a very good procedure and it also seems to get me thinking more about page structure and not relying on ASP.Net events too often.

I am currently writing a wizard feature for a site, though not using the ASP.NET Wizard control, but handling it more manually with a MultiView. Typically in the past I would have expected the typical user experience to be GET > POST > POST > POST etc. for each successive step of the wizard. However I am now thinking of using a more P/D/G approach, do people often do this with their wizards?

My current thinking is that once a step has been completed by a user and they choose to continue, my session object containing the current wizard information will be saved back to the session and then a GET redirect will be made back to the wizard page. When the wizard page loads the Session object is interrogated to determine the correct step to display to the user.

I can see two good advantages with this:

  1. that it comes with the usual benefit of P/R/G and it eliminates the Refresh problem and also
  2. a user can navigate away from the wizard and come back to it (if their session is still active) and they will be taken straight to the correct step.

Do people consider this a cleaner design? Are there obvious drawbacks? I'm thinking I might be turning into more of a cynical programmer and trusting ASP.Net and the Postback lifecycle less, but it's not as if this approach will result in much more code? If I didn't implement it I'd have to write in all the checks against a user refreshing or trying to navigate to steps they shouldn't anyway.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

窗影残 2024-10-12 16:18:07

是的,这是一个更干净的设计。

唯一的缺点是额外的往返(用于重定向)和 显示状态消息的复杂性略有增加

我再也不会将 POST 结果返回给用户了。

Yes this is a cleaner design.

The only drawbacks are the additional roundtrip (for the redirect) and the slightly increased complexity of displaying status messages.

I never return POST results to users anymore.

孤君无依 2024-10-12 16:18:07

正如您所描述的,该方法的一个问题是没有“返回”功能,这是向导的典型期望。另外,请注意,有人可能希望能够在不同的浏览器选项卡中同时完成向导的多个“会话”,而您的系统会阻止这种情况发生。

“后退”功能可以包含在“后退”链接/按钮中放置的特殊查询字符串值中,该值指示会话存储对象备份步骤。一个会话中的多个实例需要更多的参与;也许只是将数据存储在视图状态中,或者为“向导实例”创建一个键。或者,您可能决定只支持向导的单个实例在任意时间运行。 (诚​​然,无论如何,有人尝试同时运行多个向导实例的情况可能极为罕见)

One problem with the approach as you have described it is there is no 'back' functionality, which is a typical expectation with Wizards. Also, be aware that someone may expect to be able to progress through multiple 'sessions' of the wizard at the same time in different browser tabs, and your system would prevent that.

The 'Back' functionality can be included with a special Query String value put in the 'Back' link/button which instructs the session-stored object to back things up a step. The multiple-instance in one session would require something more involved; perhaps simply storing the data in the view state, or creating a key for the 'wizard instance'. Or, you may decide to only support a single instance of the wizard to run at any one time. (admittedly, it may be an extremely rare case that someone tries to run multiple wizard instances at once, anyway)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文