我有download.aspx
页。在Page_Load
事件中,我从url下载文件并增加下载次数并存储到数据库。
刷新页面时,下载数量增加。如果我拒绝下载,数量也会增加。
我想从浏览器保存文件时增加计数。
我的代码如下
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string url = "http://localhost:5045/Documents/sample.pdf";
DownLoadFile(url);
//This is code for download counter do entry in database
SoftwareController.SoftwareDownloadHistoryEdit(0, Id, CommonController.GETMyIP(), false, "ADD");
}
}
protected void DownLoadFile(string URL)
{
System.Net.WebClient net = new System.Net.WebClient();
Response.ClearHeaders();
Response.Clear();
Response.Expires = 0;
Response.Buffer = true;
Response.AddHeader("Content-Disposition", "Attachment;FileName=");
Response.ContentType = "APPLICATION/octet-stream";
Response.BinaryWrite(net.DownloadData(URL));
Response.End();
}