如何停止不必要的回传 [英] How to stop unwanted postback

查看:110
本文介绍了如何停止不必要的回传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.NET C#工作。在按钮单击事件我想保存的东西它的做工精细,但preSS浏览器的刷新按钮后,这个事件我想阻止这种事件再次发生。

I work on ASP.NET C#. Under button click event I want to save something it's work fine, but after press the refresh button of browser, this event occurs again I want to stop this event.

推荐答案

关于这个主题的文章。

preventing重复插入记录的页面刷新

方法1

Approach 1

有一个简单的解决方案是
  的Response.Redirect回到同一
  后INSERT命令是页
  调用。这将调出页面
  没有传送任何柱接头
  给它。使用Request.Url.ToString()
  作为第一个参数
  的Response.Redirect将引起两个
  URL和页面的查询字符串是
  列入重定向。指某东西的用途
  false作为第二个参数将
  SUP preSS自动到Response.End
  其它情况下可能产生
  ThreadAbortedException。一个
  这种方法的缺点在于
  已被建立起来的的ViewState
  将丢失。

A simple solution is to Response.Redirect back to the same page after the INSERT command is called. This will call up the page without transmitting any post headers to it. Using Request.Url.ToString() as the first parameter of Response.Redirect will cause both the URL and the page's querystring to be included in the redirect. The use of false as the second parameter will suppress the automatic Response.End that may otherwise generate a ThreadAbortedException. A disadvantage of this approach is that any ViewState that had been built up will be lost.

方法2

Approach 2

一个相关的办法是对的形式提交到中间处理页面,然后Response.Redirect的回调用页面,类似于传统的ASP的方式,形成加工。这具有如只需在Button_Click事件中使用的Response.Redirect因此具有相同的缺点,具有为网站开发人员来管理创建另一页的附加的缺点相同的效果。

A related approach would be for the form to submit to an intermediate processing page and then Response.Redirect back to the calling page, similar to the classic ASP approach to form processing. This has the same effect as simply using the Response.Redirect in the Button_Click event so it has the same disadvantages, with the added disadvantage of creating another page for the website developer to manage.

方法3

Approach 3

下一批解决方案的工作原理
  确定该用户是否具有
  在浏览器刷新页面
  而不是pressing表单的提交
  按钮。所有这些解决方案的依赖
  网站上的能够使用
  成功Session变量。如果
  该网站使用基于Cookie
  会话,但用户的浏览器是否
  不允许使用cookies,这些的
  解决方案将所有的失败。
  此外,应会议
  过期这些解决方案也将
  失败。

The next batch of solutions works by determining whether the user has refreshed the page in the browser instead of pressing the form's submit button. All of these solutions depend on the ability of the website to use Session variables successfully. If the website uses cookie-based Sessions, but the user's browser does not permit the use of cookies, these solutions would all fail. Additionally, should the Session expire these solutions would also fail.

办法4

Approach 4

如果用户以某种方式设法
  规避描述的上述解决方案
  以上,防守的最后一行是在
  数据库。有两种方法
  可以采用以prevent一个
  被插入重复记录
  到数据库中。对于每一种方法,
  我搬到了SQL code到存储
  过程中,由于现在有更多的
  处理步骤涉及这些
  更容易说明在一个单独的
  存储过程。不过请注意,一个
  存储过程是不严格
  为了要求这些方法
  的工作。

Should the user somehow manage to circumvent the above mentioned solutions described above, the last line of defense is at the database. There are two methods that can be employed to prevent a duplicate record from being inserted into the database. For each method, I've moved the SQL code into a stored procedure, since there are now more processing steps involved and these are easier to illustrate in a separate stored procedure. Note however that a stored procedure is not strictly required in order for these methods to work.

这篇关于如何停止不必要的回传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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