正常流程

正常的从服务器端下载文件的流程
System.IO.FileInfo file = new System.IO.FileInfo(s_path);
HttpContext.Current.Response.ContentType = "application/ms-download";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Type", "application/octet-stream");
HttpContext.Current.Response.Charset = "utf-8";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8));
HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
HttpContext.Current.Response.WriteFile(file.FullName);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.End();

调试

对于最后一句代码HttpContext.Current.Response.End();
此语句执行后 后面的代码就不会被执行。
查看Log日志中记录的Exception的信息,显示HttpContext.Current.Response.End()这条语句正在停止进程,也就是不会再执行后面的代码。

总结

如果在调用该方法后还有要执行的代码,就注释掉最后一句代码。
即为:
System.IO.FileInfo file = new System.IO.FileInfo(s_path);
HttpContext.Current.Response.ContentType = "application/ms-download";
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Type", "application/octet-stream");
HttpContext.Current.Response.Charset = "utf-8";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(file.Name, System.Text.Encoding.UTF8));
HttpContext.Current.Response.AddHeader("Content-Length", file.Length.ToString());
HttpContext.Current.Response.WriteFile(file.FullName);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Clear();
//注释该行代码
//HttpContext.Current.Response.End();

最新文章

  1. python学习之深入
  2. FragmentStatePageradapter 与 FragmentPageradapter的区别
  3. October 11th 2016 Week 42nd Tuesday
  4. Why we need model on Django ?
  5. class属性中为什会添加非样式的属性值?
  6. python(五)图形用户界面easyGUI入门
  7. (IOS)签名Demo
  8. 去除android或者iOS系统默认的一些样式总结
  9. 如何去掉(隐藏)系统的StatusBar(状态栏)
  10. 【interview】Microsoft面经
  11. mshcMigrate制作的mshc文件中有链接打不开
  12. 设计模式(三)Singleton Pattern单例设计模式
  13. JFinal3.0 sql管理与动态生成
  14. 利用ML&AI判定未知恶意程序——里面提到ssl恶意加密流检测使用N个payload CNN + 字节分布包长等特征综合判定
  15. Unix考古记:一个“遗失”的shell
  16. LeetCode: Set Matrix Zeroes 解题报告
  17. MapReduce学习
  18. 【有上下界网络流】【ZOJ】2314 Reactor Cooling
  19. qt程序运行时的错误error:undefined reference to `_imp___ZN10QTcpSocketD1Ev'
  20. sql中where以后and和or的用法

热门文章

  1. C语言初级编程实践:2048小游戏
  2. 【mq读书笔记】定时消息
  3. [BUGCASE]Webpack打包报JavaScript堆内存泄漏的错误
  4. [整理]qbxt集训10场考试 大 杂 烩 (前篇)
  5. EF Core 执行SQL语句和存储过程
  6. k8s实验操作记录文档
  7. 第八章 Python类中常用的特殊变量和方法
  8. 第11.15节 Python正则表达式转义符定义的特殊序列
  9. PyQt(Python+Qt)学习随笔:Designer中QDialogButtonBox确认clicked信号是哪个按钮发送的方法
  10. buu学习记录(下)(做题是不可能做题的)