简体   繁体   English

如何在asp.net webforms中正确实现PRG模式

[英]How to implement PRG pattern properly in asp.net webforms

I have a simple three page asp.net webforms site and having an issue with the back browser button that throws the popup "...Firefox must send any information that will repeat any action.." when hitting back on the step3.aspx. 我有一个简单的三页asp.net webforms网站,并且有一个问题,后面的浏览器按钮会弹出弹出窗口“...... Firefox必须发送任何可以重复任何操作的信息......”,当回到step3.aspx时。

The flow is: user lands on step1.aspx, session starts, and a user quotes on a product and gets redirected to step2.aspx. 流程为:用户登陆step1.aspx,会话启动,用户在产品上引用并重定向到step2.aspx。 On step2.aspx, you confirm the purchase by clicking an asp:Button. 在step2.aspx上,单击asp:按钮确认购买。 The OnClick event handler, btnPurchase_Click, handles the logic for purchase and redirects, Response.Redirect("step3.aspx"), to step3.aspx. OnClick事件处理程序btnPurchase_Click处理购买和重定向的逻辑,Response.Redirect(“step3.aspx”)到step3.aspx。 Step3.aspx simply displays the confirmation page (receipt details). Step3.aspx只显示确认页面(收据详情)。 The session is destroyed on step3 and when the user hits the back browser button, they are prompted with the resubmit post popup. 会话在步骤3中被销毁,当用户点击后面的浏览器按钮时,会提示他们重新提交帖子弹出窗口。 Ideally, I want the user to hit step1 on hitting back without the resubmit prompt. 理想情况下,我希望用户在没有重新提交提示的情况下点击返回step1。 Each page is set to no-cache and redirects to step1 if session is invalid. 如果会话无效,则每个页面都设置为no-cache并重定向到step1。

Does anyone have a suggestion for a better flow? 有没有人建议更好的流量?

This site will eventually be migrated to asp.net mvc/ajax which will most likely make the PRG workflow easier to implement but for now, looking for a relatively simple way. 该站点最终将迁移到asp.net mvc / ajax,这很可能使PRG工作流程更容易实现,但是现在,寻找一种相对简单的方法。

A simple solution is to never allow a page to render on postback, but instead accept/store whatever information it was posted, and then redirect to the next page (or itself). 一个简单的解决方案是永远不允许页面在回发时呈现,而是接受/存储它发布的任何信息,然后重定向到下一页(或自身)。

That way if a user hits the back button, it is going back to a GET, not a POST, and avoids the popup. 这样,如果用户点击后退按钮,它将返回到GET,而不是POST,并避免弹出窗口。

I give this question a try. 我试试这个问题。 The flow you mention will obstruct the pages normal function, which you of course already have in mind. 你提到的流程会阻碍页面正常功能,你当然已经想到了这一点。 Though, i would say it can be dangerous (against the function you expect) and contraproductive. 虽然,我会说它可能是危险的(违背你期望的功能)和反效果。 Based on what I can see from your question, I would definitively remove Page2 and Page3 and keep all logic in same and single page. 根据我在您的问题中可以看到的内容,我最终会删除Page2和Page3,并将所有逻辑保持在同一页面中。

I would also be happy to hear what you are trying to avoid, with this? 我也很高兴听到你想要避免的事情吗? Is it double posts? 这是双职位吗? Like a double-post of a content in a shopping cart? 就像购物车中的双重内容一样? Partial / uncomplete inserts of data input? 部分/不完整的数据输入插入? With the described way to affect back-buttons, you may come around one problem but rise another. 通过所描述的影响后退按钮的方法,您可能遇到一个问题,但又会出现另一个问题。 A big range of browsers that can act completely different on such work-arounds. 各种各样的浏览器可以在这些解决方案上完全不同。

I see two good options, 我看到两个不错的选择,

UserControl, 用户控件,
Create three UserControls which every each of them have each page specific logic. 创建三个UserControl,每个UserControl都有每个页面特定的逻辑。 You can programmatically load them into the page. 您可以以编程方式将它们加载到页面中。 Ie on bnButton_Click Event. bnButton_Click事件。 Usercontrols are loaded with LoadControl("PathToAscxFileOnDisk.ascx") . Usercontrols使用LoadControl("PathToAscxFileOnDisk.ascx")加载。

Panels, 面板,
I would also think about three <asp:PlaceHolder></asp:PlaceHolder> or perhaps better <asp:Panel></asp:Panel> to put all logic into. 我还会考虑三个<asp:PlaceHolder></asp:PlaceHolder>或者更好的<asp:Panel></asp:Panel>来放入所有逻辑。

In this case you are completely free from the postback issues and can focus on moving your functions into business logic and have use the Code-File to control the flow on show/hide and populate the controls in/out from the panels/usercontrols. 在这种情况下,您完全没有回发问题,可以专注于将您的功能转移到业务逻辑中,并使用代码文件来控制显示/隐藏的流程,并从面板/用户控件中填充/输出控件。 You can probably also control the postback / click-URL & push-enter-key. 您也可以控制回发/点击URL和push-enter-key。

And you mentioned Ajax, 你提到了Ajax,
Ajax is absolutely there to make your page stateless (which means you can work without cache, sessions, viewstate and so on. Though, the problem lies in the users possibility to navigate between pages. I would think even Ajax is of less help, while you keep the three-pages-solution. Ajax绝对可以使您的页面无状态(这意味着您可以在没有缓存,会话,视图状态等的情况下工作。但问题在于用户在页面之间导航的可能性。我认为即使是Ajax也没什么帮助,而你保持三页的解决方案。

I would personally say it is a simple task to move the aspx files into each ascx and create a aspx as a master-container. 我个人会说,将aspx文件移动到每个ascx中并将aspx创建为主容器是一项简单的任务。 With that option you even avoid duplicate namings (like if you copy / paste the code into panels) and trouble with Page_Load flow/logic. 使用该选项,您甚至可以避免重复的命名(例如,如果将代码复制/粘贴到面板中),并且使用Page_Load流/逻辑会出现问题。

If I understand correctly you're not yet using the PRG. 如果我理解正确,你还没有使用PRG。

On step 2, temporarily store the information and redirect to show it. 在步骤2中,临时存储信息并重定向以显示它。 How you do so depends a lot on your application: session, database, cookies, etc are all options with different caracteristics. 你如何这样做取决于你的应用程序:会话,数据库,cookie等都是具有不同特征的选项。

Then redirect to show that information. 然后重定向以显示该信息。

Same goes on step 3. 第3步也是如此。

If you hit back on step 3, you'll go to step 2. But given you're going back to a GET request, there won't be a warning. 如果你回到第3步,你将转到第2步。但是如果你回到GET请求,就不会有警告。 Like you said, your application destroys the session data on 3, so according to what you said the user would go to step3. 就像你说的那样,你的应用程序会破坏3上的会话数据,所以根据你的说法,用户会转到第3步。

Maybe I'm missing something on what you said. 也许我错过了你说的话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Asp.Net Webforms中实现插件体系结构 - How to implement plugin architecture into Asp.Net webforms 如何在 ASP.NET 4 webforms 中实现 google Authenticator? - How to implement google Authenticator In ASP.NET 4 webforms? asp.net webforms路由无法正常工作 - asp.net webforms routing not working properly 如何在asp.net webforms中使用HttpClient - How to use HttpClient in asp.net webforms 如何使用ASP.NET WebForms和现有SQL Server数据库实现登录功能? - How to implement Login functionality using ASP.NET WebForms and existing SQL Server database? 如何实现授权在与不同的用户角色不同的访问权限asp.net Web表单 - How to implement Authorization in asp.net Webforms with different access rights with different user roles 如何在“旧”ASP.NET Framework WebForms 基础架构中实现 Google 的 reCAPTCHAv3? - How Do I Implement Google's reCAPTCHAv3 in the “Old” ASP.NET Framework WebForms Infrastructure? 如何在ASP.NET Web服务中实现DI模式? - How to implement DI pattern in asp.net web service? 如何在 ASP.NET CORE MVC 中正确实现分页 - How to Properly Implement Pagination in ASP.NET CORE MVC 如何在ASP.NET Webforms网站项目中一起使用Webforms和ASP.NET MVC? - How do I use Webforms and ASP.NET MVC together in an ASP.NET Webforms Website project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM