asp.net怎么统计软件的下载次数
前台页面:
<asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="ad112/img.jpg" OnClick="ImageButton1_Click" />
后台:
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
Response.ContentType = "/apk";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("test.apk", System.Text.Encoding.UTF8));
Response.TransmitFile(Server.MapPath("test.apk"));
Response.End();
}
代码如上:点击按钮弹出下载框,当点击保存的时候怎么统计次数,如果是点击直接打开或取消不算次数
[解决办法]
这个要在js判断了 return false 不计算 return true 计算 (不知道对不对) 请告诉解答
[解决办法]
在button里加个aplication吗,或者在一个表中加个字段,每次点击了button时就更新字段啊
[解决办法]
public class DownloadHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
string fileName = context.Request.QueryString["filename"].ToString();
string filePath = "path of the file on disk"; //you know where your files are
FileInfo file = new System.IO.FileInfo(filePath);
if (file.Exists)
{
try
{
//更新数据库中的下载次数
}
catch (Exception)
{
//handl.
}
//return the file
context.Response.Clear();
context.Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
context.Response.AddHeader("Content-Length", file.Length.ToString());
context.Response.ContentType = "application/octet-stream";
context.Response.WriteFile(file.FullName);
context.ApplicationInstance.CompleteRequest();
context.Response.End();
}
}
public bool IsReusable
{
get { return true; }
}
}
<httpHandlers>
<add verb="GET" path="FileDownload.ashx" type="DownloadHandler"/>
</httpHandlers>
<a href="FileDownload.ashx?filename=file.exe">Download file.exe</a>