在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
正常流程正常的从服务器端下载文件的流程
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(); |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论