邮政重定向获取asp.net [英] Post Redirect Get in asp.net

查看:158
本文介绍了邮政重定向获取asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很感兴趣,在我的网站上实施PRG某些形式的我已经创建。在present他们回发到自己,明明刷新这些页面张贴在重复的数据。任何人都可以点我的我怎么能code这到我的网站一个很好的教程的方向?我理解的逻辑,但我不知道究竟从哪里开始。
谢谢

I'm interested in implementing PRG in my website for some forms I've created. At present they postback to themselves, and obviously refreshing these pages posts the data in duplicate. Can anyone point me in the direction of a good tutorial of how I can code this into my site? I understand the logic but am not sure exactly where to start. Thanks

推荐答案

在你回发到窗体你只需要回传后执行重定向。

After you postback to the form you simply need to perform a redirect after the postback.

DoPostbackProcessing();
Response.Redirect("FormConfirmationPage.aspx");

作为一个非常简单的例子,基本上只要你重定向(GET)到另一个页面,则用户不能复制回发。当然,如果有在论坛的任何错误你可能不希望再直接,但这种下降到个性化需求。

As a very simple example, basically as long as you redirect (GET) to another page then the user cannot duplicate the postback. Of course if there are any errors in the forum you may not want to re-direct, but this is down to individual requirements.

编辑:这方面的一个很好的例子就是搜索,而不是回发,然后进行搜索,你会重定向和GET:

A good example of this is search, instead of posting back and then performing the search you would redirect and GET:

// Instead of performing search now we will redirect to ourselves with the criteria.
var url = "SearchPage.aspx?criteria=" + txtSearch.Text;
Response.Redirect(url);

这会重新定向,页面检查条件查询字符串,然后执行搜索,当用户刷新一遍搜索 - 再加上他们可以书签的页面进行即时搜索

This then redirects, the page then checks for a criteria query string and THEN performs the search, and when the user refreshes it searches again - plus they can bookmark the page for instant searching.

这篇关于邮政重定向获取asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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