具有 Post/Redirect/Get 功能的 ASP.NET 向导
我正在习惯 Post/Redirect/Get 模式,我发现它是一个非常好的过程,而且它似乎也让我更多地思考页面结构,而不是过于频繁地依赖 ASP.Net 事件。
我目前正在为站点编写向导功能,虽然没有使用 ASP.NET Wizard 控件,但使用 MultiView 更手动地处理它。通常在过去,我预计典型的用户体验是 GET >发布>发布> POST 等向导的每个后续步骤。然而,我现在正在考虑使用更多的P/D/G方法,人们经常用他们的巫师这样做吗?
我当前的想法是,一旦用户完成某个步骤并选择继续,包含当前向导信息的会话对象将被保存回会话,然后将进行 GET 重定向返回向导页面。当向导页面加载时,将询问 Session 对象以确定向用户显示的正确步骤。
我可以看到这样做有两个很好的优点:
- 它具有 P/R/G 通常的好处,它消除了刷新问题,而且
- 用户可以导航离开向导并返回到它(如果他们的会话仍然处于活动状态),他们将直接进入正确的步骤。
人们认为这是一个更简洁的设计吗?有明显的缺点吗?我想我可能会变成一个更加愤世嫉俗的程序员,并且更少信任 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:
- that it comes with the usual benefit of P/R/G and it eliminates the Refresh problem and also
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,这是一个更干净的设计。
唯一的缺点是额外的往返(用于重定向)和 显示状态消息的复杂性略有增加。
我再也不会将 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.
正如您所描述的,该方法的一个问题是没有“返回”功能,这是向导的典型期望。另外,请注意,有人可能希望能够在不同的浏览器选项卡中同时完成向导的多个“会话”,而您的系统会阻止这种情况发生。
“后退”功能可以包含在“后退”链接/按钮中放置的特殊查询字符串值中,该值指示会话存储对象备份步骤。一个会话中的多个实例需要更多的参与;也许只是将数据存储在视图状态中,或者为“向导实例”创建一个键。或者,您可能决定只支持向导的单个实例在任意时间运行。 (诚然,无论如何,有人尝试同时运行多个向导实例的情况可能极为罕见)
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)