问题描述
我有一个ASP.NET应用程序,它可以让用户从Web服务器下载文件。
我跟踪下载,并且只允许一个文件这么多的下载。
I have an ASP.NET application which lets users download files from my web server.I track the downloads, and only allow so many downloads of a file.
我有以下的code调用下载为我的用户(在点击一个按钮):
I have the following code to invoke the download for my users (on click of a button):
string sURL = sExternalSequenceFullPath + Session["sFilename"].ToString();
FileInfo fileInfo = new FileInfo(sURL);
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
Response.AddHeader("Content-Length", fileInfo.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Flush();
Response.WriteFile(fileInfo.FullName);
我的问题是,浏览器presents用户与下载(保存/另存为)或取消的能力。
My problem is that the browser presents the user with the ability to download (save/saveas) or cancel.
有没有办法知道用户是否取消?如果他们没有取消,我不想算对他们的下载。
Is there a way to know if the user cancelled? If they did cancel, I don't want to count the download against them.
如果不是,有另一种方式做[无添加一些东西到客户端的机器。
If not, is there another way to do with [without adding something to the client's machine].
推荐答案
有没有办法,我知道这是可以做到。我想present一个对话框,这将要求您的下载code用户。如果他们选择了是的对话框中,我会因此而小看他们。
There is no way that I know of this can be done. I would present the user with a dialog, that would call your download code. If they selected "Yes" to the dialog, I would count that against them.
另一种选择是编写一个插件(Silverlight的,闪光...等),让你有控制权。
The other option is to write a plugin(Silverlight, Flash...etc) so that you have control.
这篇关于ASP.NET文件下载 - 如果检测到用户取消下载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!