500Mb File Download - How to NOT read in memory? RRS feed

  • Question

  • User1668022544 posted
    Hello, I have implemented a IHttpModule to do dynamic rewriting. I have a wildcard extension in IIS 5 (windows 2000!) that maps to the aspnet isapi dll. What happens now is the following: Every file that is requested seems to be read into the aspnet_wp.exe process, with small files you don't really notice the increase in RAM, but I also have some 500 and 300MB files on the site where you suddenly see the process jumping up, and then recycling itself and displaying an error in the browser about the application being unavailable. Now is my question, how do I prevent this file from being read in RAM and just have IIS 5 handle the request? (It's a physical file on the HD) Here is the code I'm using: public class UrlRewrite: IHttpModule { private EventHandler onBeginRequest; /// <summary>Default Constructor.</summary> public UrlRewrite() { this.onBeginRequest = new EventHandler(this.HttpRequest); } /* UrlRewrite */ void IHttpModule.Dispose() { } void IHttpModule.Init(HttpApplication context) { context.BeginRequest += onBeginRequest; } /* Init */ #region HttpRequest() private void HttpRequest(object sender, EventArgs e) { HttpApplication HttpApp = sender as HttpApplication; if (HttpApp != null) { string req = HttpApp.Context.Request.Path; string localPath = HttpApp.Context.Server.MapPath(req); if (!File.Exists(localPath)) { // This was implemented because of another site while trying to solve this issue ..............dynamic stuff.......... } } /* HttpRequest */ #endregion } /* UrlRewrite */ Do I have to do something special in this method to specifically tell IIS to take back to request and handle it itself? I have spent 2 days trying to solve this issue already, without any luck :(
    Friday, September 3, 2004 8:04 PM

All replies

  • User-1391363652 posted
    I believe that's just the nature of the beast---to try to suck in the entire file in memory first before handing it off to you. I might be wrong, but there was a long discussion a while ago. I think I saw a KB article once that said exactly that. :( Look around for a third-party upload control but I'm sure their approach is smoke and mirrors, too.
    Saturday, September 4, 2004 7:36 PM
  • User1668022544 posted
    It's download that I need? ;) not upload.
    Sunday, September 5, 2004 2:54 AM
  • User1694595804 posted
    visit http://www.bestcomy.net , download the aspnetupload 2.0 demo, you can get a working example on download large file
    Saturday, September 25, 2004 9:55 AM
  • User69449789 posted
    I don't think there is any way to configure IIS to handle this for you. A few months ago I wrote an extranet application for performing document and image conversions for a large marketing firm. Some of the images that were being generated ended up being rather large, as in >1Gb. In version 1.0 I didn't quite realize how large some of the resulting images were going to be, so I was streaming the file off disk and back to the client via the response stream. This caused very bad things to start happening once the really big images started showing up. In version 2.0 I implemented a asynchronous conversions with a progress bar in the browser to show the user that their request was being handled (in the first version the browser would hang... not noticeable for images <100Mb) and I also decided to go with a file download link to allow the user to save the file to disk without having to instruct IIS to stream anything off of disk via my code. It works a lot better now and I don't have any problems with big files blowing up the server, you might want to look into it and see if you can't fix your problem in a similar manner.
    Thursday, October 14, 2004 11:13 AM
  • User1668022544 posted
    I kinda fixed it by making the file directory a new application and not have ASP.NET handle wildcards for that dir, forcing IIS to handle it again. Now I just redirect the browser to the file url and IIS serves it without having to go through ASP.NET I wished there was a cleaner way :p
    Thursday, October 14, 2004 12:01 PM
  • User-275659039 posted
    I am not sure if I am understanding your problem correctly, but check the post http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=592360 There is a code that shows how to push the file to the client in small chunks instead of reading everything in memory.
    Friday, October 29, 2004 11:22 PM