测量上传时间?
我有一个非常简单的页面,用户可以用它上传文件。仅使用服务器端 C#(例如隐藏代码),如何测量用户等待文件上传的时间量?
I have a very simple page with which a user uploads a file. Using only server-side C# (e.g. the code-behind), how can I measure the amount of time the user had to wait for the file to upload?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是非常困难的(嗯,这是在 IIS6 中)。您需要编写一个 HttpModule 来拦截上传并处理它,然后使用传入文件的总大小(位于请求的标头中),计算每秒获得的字节数,然后您可以计算还剩多少时间。
但是,仅使用代码隐藏文件无法执行任何操作 - 当请求到达 asp.net 处理程序时,该文件已经上传并可用。
This is very difficult (well, it was in IIS6). You need to write an HttpModule to intercept the upload and handle it, then using the total size of the file coming in (it's in the header of the request), calculate how many bytes per second you're getting, and then you can calculate how much time is left.
However, you cannot do any of this with just the code-behind file -- the file is already uploaded and available by the time the request gets to the asp.net handler.
我必须找到这样的东西,我正在使用这个。
I had to find something like this and I'm using this.
如果您不关心完全准确性,则可以向服务器发送快速调用以指示上传正在开始,然后立即发出上传请求。然后,服务器可以测量第一次调用和第二次调用完成之间的时间。
If you're not concerned with complete accuracy, you can send a quick call to the server to indicate that an upload is starting, followed immediately by the upload request. The server can then measure the time between the first call and the completion of the second call.