加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 为大型下载配置httpRuntime执行超时

发布时间:2020-12-16 01:34:05 所属栏目:百科 来源:网络整理
导读:在我的工作地点,我们有一个ASP.NET页面,它使用以下代码来执行文件下载.我们使用它而不是Request.TransmitFile(),因为该文件直接来自zip存档. private void DownloadStream(Stream stream) { int bytesRead; int chunkSize = 1048576; //1MB byte[] readBuffe
在我的工作地点,我们有一个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,readBuffer.Length)) > 0)
        {
            if (!Response.IsClientConnected)
                break;

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

我正在尝试确定httpRuntime executionTimeout设置的合理值.发送的文件大小最大为1GB,我们的一些用户对网络服务器的管道速度非常慢(想想64K线路).我们不希望这些用户体验连接重置.但是,我们希望为站点的其余部分保留合理的超时值.

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

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

*题外话题:“慢管”是一个令人讨厌的混合比喻吗?我应该说“小管”,但在这种情况下,这听起来很奇怪.意见?

解决方法

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读