当触发文件上传时,回发事件后面的代码是否会在文件上传完成之前触发?
我试图了解当用户从 ASP.NET Web 表单将数据发回服务器时发生的确切过程。文件上传是否始终在回发开始之前完成,或者某些处理可以在请求结束之前完成。
作为这个问题的一部分,有些人如何能够估计上传特定文件所需的时间,因为他们必须至少了解代码中发生的情况,然后假设该文件还没有完全上传?
I’m trying to get a handle on the exact process that occurs when a user posts data back to the server from an asp.net webform. Does the file upload always complete before postback starts or can some processing finish before the end of the request is finished.
As a part of this question how is it that some people are able to estimate the time it will take to upload a specific file since they would have to have at least some knowledge of what’s happening in the code and the file would then be assumed to not have completely uploaded?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可以估计上传时间并显示进度的 Web 应用程序通常使用在客户端上运行的第 3 方插件来进行上传(Flash 上传器、silverlight 上传器、java 插件、activeX 控件等)。它们通常执行异步回发并管理自己与服务器的网络连接。不过,通常是客户端代码决定上传进度和速度等。
通过 HTML 输入控件进行文件上传的标准 HTTP 支持不是很智能。因此,如果您使用 asp.net FileUpload 控件(它仅将 HTML 输入标记呈现到浏览器),您将很难从页面后面的代码获取请求,直到文件的整个上传完成。
然而;您可以在上传完整文件之前在 HttpModule 中拦截请求。 asp.net 生命周期中的一些早期事件将在文件上传完成之前触发,但老实说,我不知道在等待其余发布数据之前您到底收到了多远的请求。我确实知道 BeginRequest 被调用(我之前已经在这里连接了文件上传的代码)。
所以是的,您可以在这里做一些工作,但是此时您有关传入请求内容的信息将非常有限。
Web apps that can estimate upload times and show progress are generally using a 3rd party plug-in that runs on the client to do the uploading (flash uploader, silverlight uploader, java plug-in, activeX control, etc.). These usually perform async postbacks and manage their own network connection to the server. It is usually the client-side code that is determinning the upload progess and speed and such though.
The standard HTTP support for file uploads through the HTML input control is not very intelligent. So if you are using the asp.net FileUpload control (which just renders an HTML input tag down to the browser) you will have a hard time getting at the request from the page's code behind until the entire upload of the file is complete.
However; you can intercept the request in an HttpModule before the complete file is uploaded. Some of the earlier events in the asp.net lifecycle will fire before the file upload completes, but honestly I don't know exactly how far into the request you get before it waits for the rest of the post data. I do know that BeginRequest gets called though (I've hooked up code here for file uploads before).
So yes, you can do some work here, but your information about the content of the incoming request will be very limited at that point.