ASP.Net Count下载点击次数

Mar*_*rco 1 asp.net count download onclick

我觉得这更容易......

我有一个asp:超链接控件,target=”_blank”指向我希望用户下载的文件.我的计划是跟踪用户点击此链接的次数.

我想将它放在ajax更新面板中,以捕获回发并避免整页刷新.

但是,超链接没有onClick方法.

在另一方面,我可以使用linkbutton,它有一个onClick建于但是这是很难使文件在新窗口中打开...我也必须这样做:

Response.AppendHeader("Content-Disposition","attachment; filename=myImage.jpg");
Run Code Online (Sandbox Code Playgroud)

但我听说上面的方法在PPT,PPTX,PPS,PPSX等方面存在一些问题......

你对这个有什么看法?怎么以及为什么,你会这样做吗?

M4N*_*M4N 5

您可能希望实现IHttpHandler来跟踪下载,例如本文所示.

基本上你的处理程序的ProcessRequest()方法看起来像这样:

public void ProcessRequest(HttpContext context)
{
    string file = context.Request.QueryString["file"];

    // set content type and header (PDF in this example)
    context.Response.ContentType = "application/pdf";
    context.Response.AddHeader(
         "Content-Disposition", "attachment; filename=" + file);

    // assuming all downloadable files are in ~/data
    context.Response.WriteFile(Server.MapPath("~/data/" + file));
    context.Response.End();
}
Run Code Online (Sandbox Code Playgroud)

然后你下载文件的超链接将是这样的:

<a href="/MyApp/MyHandler.ashx?file=someFile.pdf">...</a>
Run Code Online (Sandbox Code Playgroud)