为大量下载配置 httpRuntime 执行超时
在我的工作场所,我们有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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
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