views:

706

answers:

1

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?

+2  A: 

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
Ahh, that's what I was looking for. Obviously, I'm new to asp.net. Thanks!
Odrade