双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

asp.net 下載異常 “執行緒已終止”

qq3895 qq3895 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

try
{
string FilePath = "";
if (path.Contains("~"))
{
FilePath = HttpContext.Current.Request.MapPath(path);
}
else
{
FilePath = path;
}
System.IO.FileStream r = new System.IO.FileStream(FilePath, System.IO.FileMode.Open);
//设置基本信息
HttpContext.Current.Response.Buffer = false;
HttpContext.Current.Response.AddHeader("Connection", "Keep-Alive");
HttpContext.Current.Response.ContentType = "application/octet-stream;";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
HttpContext.Current.Response.Charset = "utf-8";
//HttpUtility.UrlEncode解决中文文件名乱码问题
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName).Replace("+", "%20"));
HttpContext.Current.Response.AddHeader("Content-Length", r.Length.ToString());
try
{
while (true)
{
//开辟缓冲区空间
byte[] buffer = new byte[1024];
//读取文件的数据
int leng = r.Read(buffer, 0, 1024);
if (leng == 0)//到文件尾,结束
break;
if (leng == 1024)//读出的文件数据长度等于缓冲区长度,直接将缓冲区数据写入
HttpContext.Current.Response.BinaryWrite(buffer);
else
{
//读出文件数据比缓冲区小,重新定义缓冲区大小,只用于读取文件的最后一个数据块
byte[] b = new byte[leng];
for (int i = 0; i < leng; i++)
b[i] = buffer[i];
HttpContext.Current.Response.BinaryWrite(b);
}
}
r.Close();//关闭下载文件
HttpContext.Current.Response.End();//结束文件下载
}
catch (Exception ex)
{
string[] strMsg = { "Message:" + ex.Message, "Source:" + ex.Source, "StackTrace:" + ex.StackTrace };
fileHandling("File", strMsg);
return false;
}
}
catch (Exception ex)
{
string[] strMsg = { "Message:" + ex.Message, "Source:" + ex.Source, "StackTrace:" + ex.StackTrace };
fileHandling("File", strMsg);
return false;
}
return true;

這是我的下載代碼,本地調試時沒有問題,可以下載,可是放到服務上,點擊鏈接下載時沒有反應,我的log文件記錄到的錯誤是”執行緒已終止“什麽的
求解!!!!!!

急!!!!!!!

...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
qq3895
.NET社区 62,274 成员 668,968 内容