Providing downloads on ASP.net

I need to ensure that large files (over 2 GB) are uploaded to the ASP.net website. Some time has passed since I did something like this (I have been in the world with a fat client for some time), and wondered about modern best practices for this. Ideally, I would like to:

  • To be able to track download statistics: you need a large number of downloads; the actual bytes sent will be nice.
  • Provide downloads so as to โ€œplay wellโ€ with third-party download managers. Many of our users have unreliable Internet connections, and the ability to resume downloading is a must.
  • Allow multiple users to download the same file at the same time.

My download files are not security sensitive, so providing a direct link ("right click to download ...") is an option. Is simply providing a direct link sufficient, allowing IIS to process it, and then using some log analyzer service (any recommendations?) To compile and send statistics? Or do I need to intercept a download request, store some information in a database, and then send a custom response? Or is there an ASP.net user control (built-in or third-party) that does this? I appreciate all the suggestions.

+4
source share
1 answer

I have used custom HTTP handlers to provide this feature in the past. I created the download.axd file and wrote a simple HttpHandler.

public class DownloadHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { // Do some logging to track stats. // Set some custom response headers context.Response.TransmitFile(filename); } } 

Important information about the TransmitFile method is that it sends the file in response without storing the file in memory. This will be important in your case, as you are dealing with large files.

You also need to register the handler in your web.config:

  <httpHandlers> <add verb="GET,HEAD" path="download.axd" type="DownloadHandler, MyAssemby"/> </httpHandlers> 

Still using this approach, it will be difficult to track the actual bytes sent to each user downloading.

+3
source

Source: https://habr.com/ru/post/1310370/


All Articles