Post Redirect Get in asp.net [英] Post Redirect Get in asp.net

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

问题描述

我有兴趣在我的网站中为我创建的某些表单实施 PRG.目前他们回传给自己,显然刷新这些页面会重复发布数据.谁能指出我如何将其编码到我的网站的良好教程的方向?我理解逻辑,但不确定从哪里开始.谢谢

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.

一个很好的例子是搜索,而不是回发然后执行搜索,你会重定向和获取:

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.

这篇关于Post Redirect Get in asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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