亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

這段下載代碼有什么問題嗎

這段下載代碼有什么問題嗎

慕田峪9158850 2018-12-07 07:21:12
try { string filepath = context.Server.MapPath(context.Request.QueryString["filedir"].ToString() + "/" + context.Request.QueryString[0].Substring(0, 4).ToString() + "/" + context.Request.QueryString[0].ToString()); string filename = context.Request.QueryString[1].ToString(); FileInfo info = new FileInfo(filepath); long fileSize = info.Length; context.Response.Clear(); context.Response.ContentType = "application/x-zip-compressed"; context.Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename, System.Text.Encoding.UTF8)); //不指明Content-Length用Flush的話不會顯示下載進度 context.Response.AddHeader("Content-Length", fileSize.ToString()); context.Response.TransmitFile(filepath, 0, fileSize); context.Response.Flush(); context.Response.Close(); } catch { } 為什么會在99%時卡住,要等個幾分鐘才結束,也不是每次都這樣,求指導,或者誰給個自己用的順手的下載代碼,謝謝。
查看完整描述

4 回答

?
一只甜甜圈

TA貢獻1836條經驗 獲得超5個贊

在Catch中調試或者加日志記錄,我懷疑有可能爆異常了 。TransmitFile這個方法拿來干什么的?
查看完整回答
反對 回復 2018-12-09
?
明月笑刀無情

TA貢獻1828條經驗 獲得超4個贊

一樓正解,確定zip之后的文件長度一樣?
查看完整回答
反對 回復 2018-12-09
?
UYOU

TA貢獻1878條經驗 獲得超4個贊

你把? context.Response.Flush(); context.Response.Close(); 換成 context.Response.End(); ?
查看完整回答
反對 回復 2018-12-09
?
慕后森

TA貢獻1802條經驗 獲得超5個贊

這個是把文件當做zip格式傳遞給客戶端,和fileSize 大小有關吧,越大的文件時間越長
查看完整回答
反對 回復 2018-12-09
  • 4 回答
  • 0 關注
  • 385 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號