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; /// Default Constructor. 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 :(
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.
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.
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
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.
Member
10 Points
410 Posts
500Mb File Download - How to NOT read in memory?
Sep 03, 2004 08:04 PM|CumpsD|LINK
public class UrlRewrite: IHttpModule { private EventHandler onBeginRequest; /// Default Constructor. 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 :(Member
130 Points
293 Posts
Re: 500Mb File Download - How to NOT read in memory?
Sep 04, 2004 07:36 PM|MilanNegovan|LINK
http://www.AspNetResources.com
ASP.NET With Emphasis On Web Standards
Member
10 Points
410 Posts
Re: 500Mb File Download - How to NOT read in memory?
Sep 05, 2004 02:54 AM|CumpsD|LINK
None
0 Points
26 Posts
Re: 500Mb File Download - How to NOT read in memory?
Sep 25, 2004 09:55 AM|comy|LINK
None
0 Points
3 Posts
Re: 500Mb File Download - How to NOT read in memory?
Oct 14, 2004 11:13 AM|MagicWishMonkey|LINK
Member
10 Points
410 Posts
Re: 500Mb File Download - How to NOT read in memory?
Oct 14, 2004 12:01 PM|CumpsD|LINK
None
0 Points
673 Posts
Re: 500Mb File Download - How to NOT read in memory?
Oct 29, 2004 11:22 PM|exptrade2000|LINK