views:

122

answers:

2

I have an ashx handler with the following code. The idea is to hide the path of the file and prompt a download

       context.Response.Clear();
       context.Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
       context.Response.AddHeader("Content-Length", file.Length.ToString());
       context.Response.ContentType = "application/octet-stream";
       context.Response.WriteFile(file.FullName);

This works fine for some files however on others i get

Exception of type 'System.OutOfMemoryException' was thrown.

A: 

You have filled system memory. With larger files, transferred data is buffered in memory. I would suggest creating your own custom caching method.

Melvin
+3  A: 

Very weird, 7Mb is really small. Maybe there's a low limit on your Application Pool ?

If you only need a file download handler, use HttpResponse.TransmitFile() which don't buffer the file in memory.

http://msdn.microsoft.com/en-us/library/12s31dhy%28VS.80%29.aspx

JoeBilly
@joe, see in this page http://msdn.microsoft.com/en-us/library/e1f13641.aspx, httpRuntime -> maxRequestLength and probably appRequestQueueLimit --- did I make wrong ?
Aristos
@Aristos, Oh I see ! You mistake **Request** limit and **Response** limit ;) Since the file is transmitted by the server, its a response and not a request. And a Request limit don't throw OutOfMemoryException which mean a real memory problem.
JoeBilly
+1 Ok thank you for the info.
Aristos