ASP.Net Count Download Clicks

雨燕双飞 提交于 2019-12-02 05:48:15

You might want to implement an IHttpHandler to track your downloads, as shown in this article for example.

Basically your handler's ProcessRequest() method would look something like this:

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();
}

Then your hyperlink to download a file would be like this:

<a href="/MyApp/MyHandler.ashx?file=someFile.pdf">...</a>

You can add an onclick to an asp hyperlink like so:

aHyperlinkControl.Attributes.Add("onclick", "jsCallToSendCountToServer();");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!