首页 新闻 搜索 专区 学院

IIS - 流方式下载文件:网络错误

0
悬赏园豆:30 [待解决问题]

Windows Server 2008 R2 IIS下载文件,通过URL直接访问文件地址,可以成功下载,通过流方式下载,提示网络错误(如下图),但是部署我本地Windows 10 IIS,可以通过流方式正常下载。哪位大神可告知!


流方式下载代码,如下:

 byte[] buffer = new byte[102400L];
 HttpContext.Current.Response.Clear();
 FileStream fileStream = File.OpenRead(fileInfo.FullName);
 long num = fileStream.Length;
 HttpContext.Current.Response.ContentType = "application/octet-stream";
 HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" 
 + HttpUtility.UrlEncode(savename, Encoding.UTF8));
 HttpContext.Current.Response.AddHeader("Content-Length", fileInfo.Length.ToString());
 while (num > 0L && HttpContext.Current.Response.IsClientConnected)
 {
          int num2 = fileStream.Read(buffer, 0, Convert.ToInt32(102400L));
          HttpContext.Current.Response.OutputStream.Write(buffer, 0, num2);
          HttpContext.Current.Response.Flush();
          num -= (long)num2;
  }
  HttpContext.Current.Response.Close();
  fileStream.Close();
  fileStream.Dispose();
小小一菜鸟的主页 小小一菜鸟 | 初学一级 | 园豆:100
提问于:2021-12-02 09:11
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册