Yes There are several ways to do this. here is how you can do it.
Instead of submitting an mp3 file from a disc with a direct link, for example <a href="http://mysite.com/music/song.mp3"></a> , write HttpHandler to download the file. In HttpHandler you can update the number of download files in the database.
Download HttpHandler File
//your http-handler 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 { //increment this file download count into database here. } catch (Exception) { //handle the situation gracefully. } //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; } } }
Web.config configuration
//httphandle configuration in your web.config <httpHandlers> <add verb="GET" path="FileDownload.ashx" type="DownloadHandler"/> </httpHandlers>
Link file upload from frontend
Additionally , you can map the mp3 extension in web.config to HttpHandler. To do this, you will need to make sure that you configure IIS to redirect .mp3 extension requests to the asp.net workflow and do not serve directly, and also make sure that the mp3 file is not in the same place as the capture handler if the file is located on the disk in the same place, the HttpHandler will be overloaded, and the file will be sent from the disk.
<httpHandlers> <add verb="GET" path="*.mp3" type="DownloadHandler"/> </httpHandlers>
this. __curious_geek
source share