如何在asp.net WebForms中实现“发布/重定向/获取"模式? [英] How do I implement the Post/Redirect/Get pattern in asp.net WebForms?

查看:80
本文介绍了如何在asp.net WebForms中实现“发布/重定向/获取"模式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我了解prg模式的基础.但是我还没有遇到一种使任意数据可用于页面获取"实例的技术.

So I understand the basics of the prg pattern. But I haven't come across a technique for making arbitrary data available to the "get" instance of a page.

例如,我可能想向用户显示不同的反馈消息,这取决于他们发起回发的动作.

For example, I might want to display different feedback messages to the user depending on their action which initiated the PostBack.

我一直在做的是发送一个标识符作为查询字符串参数.效果很好,但是它会引入书签问题,而且扩展性似乎不太好.如果我需要发送所有ViewState怎么办?

What I've been doing is sending an identifier as a query string parameter. This works fine but it introduces bookmarking issues and doesn't seem like it would scale very well. What if I needed to send all of the ViewState?

不幸的是,此刻我与WebForms捆绑在一起,无法说服我的组织迁移到mvc.

Unfortunately, I'm tied to WebForms at the moment and haven't been able to convince my organization to migrate to mvc.

推荐答案

如果POST字段在重定向之前一直存在,并且您需要在重定向之后访问该数据,我将在数据记录后附加标识符您提到的查询字符串上.您还可以为请求指定状态(用于显示消息等).然后,在GET页面上,您可以读出数据并对其执行任何操作.

If the fields POSTed are being persisted before the Redirect and you need to access that data after the Redirect, I would append the identifier for the data record(s) on the query string as you mention. You could also specify a status for the request (for displaying messages etc). Then on the GET page you can read out the data and do whatever with it.

我没有其他解决方法,因为GET获取的每个页面都无法访问上一页的ViewState等.

I don't see any other way to get around this as each page obtained by GET will not have access to the previous page's ViewState etc.

使用Server.Transfer与在原始页面上处理POST具有相同的效果.

Using Server.Transfer will have the same effect as handling the POST on the original page.

您可以使用Session变量来存储POST数据,但是那很臭.

You could use Session variables to store the POST data, but that stinks.

这篇关于如何在asp.net WebForms中实现“发布/重定向/获取"模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆