处理浏览器刷新 [英] Handling browser refresh

查看:72
本文介绍了处理浏览器刷新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上传文档后,如果单击浏览器刷新按钮,它将再次发送请求,并且同一文档再次上传,任何人都可以提出解决此问题的最佳方法.

After uploading a document, if we click on browser refresh button,it will send the request again and the same document gets uploaded again,Can any one Suggest the best way to tackle this.

推荐答案

1.将页面重定向到新页面.让您为上传页面设置关闭缓存".因此,用户单击后退"按钮,他将无法使用页面.

2.在页面级别/用户级别/应用程序级别使用某种标记来标识已完成的上传.
1. Redirect the page to a new one. Make you set Cache off for the upload page. Hence, the user hits back button, He gets page unavailable.

2. Use a Flag of some sort at Page level/user Level/Application level to identify a completed upload.


这就是为什么您需要服务器部分来区分上传之前和之后的状态.

假设您使用"POST"方法在页面上创建表单,并且目标URI将与form标记的action属性所指定的引荐页面相同.您会感觉到一些数据,其中一部分是文件.当您单击提交"按钮开始上载时,将收到HTTP响应,该页面具有相同的URI.当服务器端生成此页面时,它具有一些要考虑的信息:1)发布数据不为空; 2)实际存在于服务器文件系统中的上载文件.由于HTTP协议是无状态的,因此您应该依赖状态的某种变化,因为它存储在服务器端.文件的存在是更改之一;这是一个非常简单的示例.

在更复杂的情况下,您可能希望跟踪某些用户或更多用户提交文件的历史记录.该数据可以存储在数据库中,并用作HTTP请求之间可用的持久状态数据.每当您处理HTTP请求并生成HTTP响应时,无论您的请求URI是相同还是不同,都可以使用此数据相应地修改响应-它不携带状态信息.

通常,您使用会话状态管理,请参阅:
http://msdn.microsoft.com/en-us/library/ms178581.aspx [ ^ ].

另请参阅本文: http://msdn.microsoft.com/en-us/magazine/cc163730.aspx [ ^ ].

请同时参阅以下CodeProject文章:
ASP.NET中的会话管理 [ ASP.NET中的会话管理选项 [ ASP.NET会话管理内部 [
That''s why your have your server part to tell the difference of the state before and after uploading.

Let''s assume you have form on the page using the method "POST", and the target URI will be the same as referral page which is prescribed by the action attribute of the form tag. You feel in some data, part of this data is the file. When you click "Submit" button you start uploading, receive HTTP response which you the page with the same URI. When a server side generates this page, it has some information to be taken into account: 1) post data is not empty; 2) the uploaded file physically present in the file system of the server. As HTTP protocol is stateless, your should rely on some change in state as it is stored on the server side; the presence of the file is one of the changes; and this is a very simple example.

In more complex situation, you may want to track the history of submissions of files by some user and more. This data can be stored in database and serves as a persistent state data available between HTTP request. Every time you process HTTP request and generate HTTP response, you can use this data to modify response accordingly, no matter if your request URI is the same or different — it does not carry state information.

In general case, you use session state management, please see:
http://msdn.microsoft.com/en-us/library/ms178581.aspx[^].

See also this article: http://msdn.microsoft.com/en-us/magazine/cc163730.aspx[^].

Please see also these CodeProject articles:
Session Management in ASP.NET[^],
Session management options in ASP.NET[^],
ASP.NET Session Management Internals[^].

—SA


一种简单的解决方案是将状态保存在已上传文件的隐藏文件中,
因此根据第2次状态,您不应再次上传文件...
One simple solution is keep the status in hidden filed that file has uploaded,
so based on the status 2nd time you should not upload the file once again ...


这篇关于处理浏览器刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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