惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
V
V2EX
WordPress大学
WordPress大学
Google DeepMind News
Google DeepMind News
Martin Fowler
Martin Fowler
小众软件
小众软件
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
The Cloudflare Blog
T
Tailwind CSS Blog
H
Help Net Security
腾讯CDC
爱范儿
爱范儿
人人都是产品经理
人人都是产品经理
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The GitHub Blog
The GitHub Blog
Microsoft Security Blog
Microsoft Security Blog
Stack Overflow Blog
Stack Overflow Blog
D
DataBreaches.Net
C
Check Point Blog
量子位
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com

博客园 - 农村的芬芳

PHP使用第三篇:生成数据库 使用THINKPHP产生的:No database selected [问题 从今天开始记录PHP使用的点点滴滴 留给自个看的工具提示 转xml Oracle 跨库 查询 复制表数据 关于海量数据处理 近日用到啦progressbar控件,将其用法留一下 select into 和 insert into select 两种表复制语句 采用regsvr32注册组件后提示:没有注册 net2005中将list<>数组转换为Table 将对象数组转换成dataset windows 服务操作 转载:XML与DataSet的相互转换类 oracle 日期函数小计 如何创建自定义帐户来运行 ASP.NET 通过ASP.net程序创建域帐户故障 EnterpriseLibrary服务问题 下载文件关闭窗体之解决方法
超级郁闷之问题,请DUDU及各位大位指正错误
农村的芬芳 · 2006-05-26 · via 博客园 - 农村的芬芳

事情皆因一文件下载惹的祸。首先我介绍我的机器构成:文件服务器,暂叫A服务器,也就是放文件的机器。应用程序服务器,这大家都明白,就是部署程序的服务器,其它服务器就不说啦。
好,开始说问题,最初小弟,根本没去想太多的性能与服务器的承载量的问题。就写了下面两段代码

string physicalFilePath = downloadpath;
                FileStream stream
=null;
                
try 
                
{
                    stream 
= new FileStream(physicalFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);    
                    
int bufSize = (int)stream.Length;
                    
byte[] buf = new byte[bufSize];

                    
int bytesRead = stream.Read(buf, 0, bufSize);
                    HttpContext.Current.Response.ContentType 
= "application/octet-stream"
                    HttpContext.Current.Response.AppendHeader(
"Content-Disposition""attachment;filename="+Server.UrlEncode(System.IO.Path.GetFileName(Server.UrlEncode(filename))));
                    HttpContext.Current.Response.OutputStream.Write(buf, 
0, bytesRead);

                    

                    HttpContext.Current.Response.End();
                }

                
finally 
                
{
                    stream.Close();
                }



或:
downloadpath为变量
System.IO.FileInfo file 
= new System.IO.FileInfo(downloadpath);
                    Response.Clear();
                    Response.Charset
="GB2312";
                    Response.ContentEncoding
=System.Text.Encoding.UTF8;
            
                    Response.AddHeader(
"Content-Disposition""attachment; filename="+Server.UrlEncode(filename));
                    Response.AddHeader(
"Content-Length", file.Length.ToString());

                                    
                    Response.ContentType 
= "application/ms-excel";
                    Response.WriteFile(file.FullName);
Response.End();

刚开始放上去时,根本没有任何问题,因为访问量与数据文件都不够大。
等过几天,访问量达到几千人同时在线时,我的问题来啦,有的数据文件也比较大,有的是100M以上的,哪上面这两种方法同时挂掉,有的因为文件太大,而无法输出,有的的有时莫明其妙的弹出服务器重置这种提示,后来我又换啦一种下载方式,代码如下:

这是从网上看到一位同仁写的,就拿过来一试,发现对大文件下载,还真不错,能顺利下载,好一段时间都没问题,心想这下可好啦,但没成想,好日子没几天,问题又接二连三的回来啦,这次的问题更莫明其妙,有的是下载到99%时,突然提示不能下载,有的呢,却一点击下载,弹出框后,就一点进度都还没有时,就一会儿弹出来一个连接超时,服务器重置的提示,把我给郁闷的,但同时呢,其它文件又可以下载用同一段代码。郁闷中ing....希望有哪位能指点一下。
文件肯定存在,链接肯定正确