为大量下载配置 httpRuntime 执行超时

发布于 2024-08-20 09:57:44 字数 964 浏览 2 评论 0原文

在我的工作场所,我们有一个 ASP.NET 页面,它使用以下代码来执行文件下载。我们使用它而不是 Request.TransmitFile() 因为该文件直接来自 zip 存档。

    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();
        }
    }

我正在尝试确定 httpRuntimeexecutionTimeout 设置的合理值。发送的文件大小最大为 1GB,并且我们的一些用户到网络服务器的管道*非常慢(想想 64K 行)。我们不希望这些用户经历连接重置。但是,我们希望为站点的其余部分保留合理的超时值。

有没有办法为此特定页面定义executionTimeout 设置(或者甚至专门对该页面进行无限制)?推荐的方法是什么?我知道我们可能最好使用完全不同的方法来提供文件(例如 FTP),但我们没有做出这种选择的自由。我们能做的就是修改网站的代码。

另外,我确实认为这些下载内容应该在发送之前进行压缩,但那是另一回事了。

*题外话:“慢管道”是一个令人烦恼的混合隐喻吗?我可能应该说“小管道”,但在这种情况下这对我来说听起来很奇怪。意见?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滴情不沾 2024-08-27 09:57:44

是否有一种方法可以仅为该特定页面定义executionTimeout 设置(或者甚至专门对该页面进行无限制)?推荐的方法是什么?

是的,您可以创建一个拥有自己的 web.config 的子目录并将
子目录中某些需要特殊设置的页面。在
此外,web.config 文件的架构还提供了该元素
这可以帮助指定特定路径(甚至特定页面)的设置。
例如,如果您想覆盖仅
一页(upload.aspx),您可以应用该元素
web.config 文件如下:

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

更多信息请参见:http://forums.asp.net/t/1235207.aspx
在这里: http://codebetter.com/博客/peter.van.ooijen/archive/2006/06/15/146446.aspx

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文