2

I'm attempting to make a website that allows large file downloads (downloads in the sense that the browser doesn't try to play the video, or display the text file. I want to force the user to choose a place to save the file) in ASP.NET v4 and IIS7, however I'm facing a few issues with this that quite frankly are annoying me.

Now, I've found a website that provides a way to stream even really large files through the http: http://www.cnblogs.com/bestcomy/archive/2004/08/10/31950.aspx

The issue with this source however is that I cannot send any other requests to the http while this file is downloading. So if a user were to try and download more than 1 file at a time, it will sit there until the first request is finished.

Is there any way to perform very large media based file downloads, that allows a user to download multiple at a time, and requires a user to choose a place to save it, as opposed to having to right click and save as?

Edit: Just to expand on this, the downloads are behind a Session page (user logged in), so I can prevent unauthorized users from downloading files (security through anonymity is not security :P ). Anyway, I can open a new browser session, and login and download another file (or the same file even), however, any further requests sit there and "load" until the download finishes.

Another Edit: I'm using the Razor MVC Framework, if that changes anything

Thanks!

dab
  • 817
  • 1
  • 12
  • 23
  • Do you need to generate the media file on the fly? If not, and they're static files, I'd just set up a separate Apache server (or several) to handle the large static files - it's what it's good at. If you want to force a download, I think you just need to override the MIME type through configuration. Copying data through your application is pretty inefficient. – millimoose Sep 10 '12 at 23:49
  • Why wouldn't you be able to download more than one file at a time? It should support it, unless you are using SessionState within that request. – Pablo Romeo Sep 11 '12 at 00:12
  • I could setup an apache server I suppose. I didn't think about it (I did think about making a C# based file server, but then again, apache is a beautiful server). I am indeed using a session state per download request. I do it for authentication before allowing the files to be downloaded (The media is not generated on the fly). I had considered doing FTP, but the point of the website was to keep the user from having to do much (Fisher Price is the goal). – dab Sep 11 '12 at 19:06

2 Answers2

2

I believe what you can do is to remove the file handler from IIS and that will cause the file to be downloaded rather than be opened. Although I have not tried this myself I think this should work. http://technet.microsoft.com/en-us/library/cc771240(v=ws.10).aspx

  • Thing is, I need some kind of "filtering" between the direct access to the files. I don't want any plain joe being able to access the files, so they have to go through an ASP page as opposed to being accessible by IIS. Thanks for the suggestion. I'll still read through it to see if it is something I might want to do. :) – dab Sep 11 '12 at 19:08
1

Now with a bit more context, I think this can be simplified quite a bit:

To allow concurrent downloads you need to ensure the Session is read-only. In MVC3 you'd decorate your controller with [SessionState(SessionStateBehavior.ReadOnly)], for your custom security checks. Now, I don't know your implementation, but take into consideration that security is usually handled through the use of the Authorize attribute or similar.

Now, to force the prompt for saving the file instead of opening it by default, check Darin's answer in the following post: https://stackoverflow.com/a/5830215/1373170

You can avoid custom code to download the file if the standard FileResult suits your needs.

Community
  • 1
  • 1
Pablo Romeo
  • 11,298
  • 2
  • 30
  • 58
  • Thing is, I need sessions to secure just anyone from being able to download the files. Perhaps I'm going about my downloads the wrong way then? – dab Sep 11 '12 at 19:59
  • And would a read-only session suffice to make that check? Try switching IRequiresSessionState for IReadOnlySessionState. The read-only version should not lock the session and allow multiple concurrent requests (http://stackoverflow.com/a/10139034/1373170) – Pablo Romeo Sep 11 '12 at 21:39
  • I originally didn't understand your comment about "HTTPHandler" Several google searches later, I can't figure out how to implement my HTTP handler. So once I figure that part out, I'll implement my download function and let you know how it goes lol (ASP/IIS newb here) – dab Sep 13 '12 at 23:48
  • Actually, an HTTPHandler would have been appropriate for an asp.net site. In your case, since you are using MVC3 you can implement all that in a controller, and change the Session Behavior, by decorating the controller with [SessionState(SessionStateBehavior.ReadOnly)] – Pablo Romeo Sep 14 '12 at 03:24
  • Wow, that got it. Thank you so much! I really thought this was going to be a futile limitation of ASP. :) Cheers man! – dab Sep 17 '12 at 19:16
  • No problem :) Glad you got it sorted out. – Pablo Romeo Sep 17 '12 at 19:31