4

At my place of work, we have an ASP.NET page that uses the following code to perform a file download. We use this rather than Request.TransmitFile() because the file is coming directly from a zip archive.

    private void DownloadStream(Stream stream)
    {
        int bytesRead;
        int chunkSize = 1048576; //1MB
        byte[] readBuffer = new byte[chunkSize];

        while ( (bytesRead = stream.Read(readBuffer, 0, readBuffer.Length)) > 0)
        {
            if (!Response.IsClientConnected)
                break;

            Response.OutputStream.Write(readBuffer, 0, bytesRead);
            Response.Flush();
        }
    }

I'm trying to determine a reasonable value for the httpRuntime executionTimeout setting. The files being sent range up to 1GB in size, and some of our users have very slow pipes* to the webserver (think 64K lines). We don't want these users to experience connection resets. However, we want to keep a reasonable timeout value for the rest of the site.

Is there a way to define an executionTimeout setting only for this specific page (or even make it unlimited for that page specifically)? What's the recommended approach? I know we'd probably be better off using a totally different method to serve the files (e.g. FTP), but we don't have the freedom to make that choice. All we can do is modify the code for the site.

Also, I do think these downloads should be compressed before sending, but that's another matter.

*Off-topic question: Is "slow pipe" an annoyingly mixed metaphor? I should probably say "small pipe" instead, but that sounds strange to me in this context. Opinions?

Odrade
  • 7,409
  • 11
  • 42
  • 65
  • Since you're generally using some good practices here, how did you arrive at a chunksize of 1MB as opposed to say 84KB (since anything larger than 85KB goes into the large object heap.) – user420667 Jul 14 '16 at 22:53
  • 1
    @user420667 It's been too long for me to remember, but given my level of experience six years ago I'd say that the choice was likely arbitrary. – Odrade Jul 15 '16 at 13:29

1 Answers1

7

Is there a way to define an executionTimeout setting only for this specific page (or even make it unlimited for that page specifically)? What's the recommended approach?


Yes, you can make a subdirectory which has a own web.config and put the certain page which need particluar setting in the subdirectory. In addition, the web.config file's schema also provide the element which can help to specify setting for a certain path (even a certain page). For example, if you'd like to override the setting for just one page(upload.aspx), you can apply the element in the web.config file as below:

http://www.velocityreviews.com/forums/t75299-executiontimeout.html

More info here: http://forums.asp.net/t/1235207.aspx
and here: http://codebetter.com/blogs/peter.van.ooijen/archive/2006/06/15/146446.aspx

Albert
  • 3,639
  • 13
  • 43
  • 58
  • Ahh, that's what I was looking for. Obviously, I'm new to asp.net. Thanks! – Odrade Feb 05 '10 at 21:30
  • I've followed those instructions and even printed on the page the value of `Server.ScriptTimeout`. Although the value printed is the one I set, the page keeps timing out after 90 seconds. Any idea of what might be missing? – Farinha Aug 08 '11 at 15:59
  • I had the same problem 2 days ago and also came across this article. It also did not work for me. I've just found out a workaround, hope it helps. Please visit this link: http://stackoverflow.com/questions/4490017/asp-net-httpruntime-executiontimeout-not-working-and-yes-debug-false – Khanh TO Apr 16 '13 at 12:17