首页 新闻 会员 周边

关于IE下用HTTPS无法下载/打开文件 ,按照网上的方法已经加了注释的代码还是不行。

0
悬赏园豆:120 [已关闭问题] 关闭于 2012-11-05 09:59

try
{ iStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read); long dataToRead = iStream.Length; HttpContext.Current.Response.ContentType = ContentType; //HttpContext.Current.Response.ClearHeaders(); //HttpContext.Current.Response.AppendHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); //HttpContext.Current.Response.AppendHeader("Pragma", "public"); //HttpContext.Current.Response.AppendHeader("Cache-Control", "public"); //HttpContext.Current.Response.Expires = 0; //HttpContext.Current.Response.CacheControl = "public"; //HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddMinutes(30)); //HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public); //在IE下重编码fileName,在火狐下就不用了! if (Request.UserAgent.IndexOf("MSIE") > -1) { HttpContext.Current.Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", this.Server.UrlPathEncode(fileName + ".xls"), Path.GetExtension(filePath))); } else { HttpContext.Current.Response.AddHeader("Content-Disposition", string.Concat("attachment; filename=", fileName, Path.GetExtension(filePath))); } while (dataToRead > 0) { if (HttpContext.Current.Response.IsClientConnected) { int length = iStream.Read(buffer, 0, buffersize); HttpContext.Current.Response.OutputStream.Write(buffer, 0, length); HttpContext.Current.Response.Flush(); buffer = new Byte[buffersize]; dataToRead = dataToRead - length; } else { dataToRead = -1; } } } catch (Exception) { SetAlertMessage("文件下载时出现错误!"); }
net.菜鸟的主页 net.菜鸟 | 初学一级 | 园豆:90
提问于:2012-10-30 12:57
< >
分享
所有回答(3)
0
// No cache.
    context.Response.Cache.SetCacheability(HttpCacheability.NoCache);
    context.Response.AppendHeader(@"Pragma",@"no-cache");
曾祥展 | 园豆:138 (初学一级) | 2012-10-30 13:11

就是因为no-cache才导致这个问题的,呵呵!

支持(0) 反对(0) net.菜鸟 | 园豆:90 (初学一级) | 2012-10-30 14:28
0

mark

ms_water | 园豆:510 (小虾三级) | 2012-10-30 13:46
0

原来是IIS的问题,IIS设置加多了一个head,所以在程序端修改不了,在HTTPS下会有两个head并存

net.菜鸟 | 园豆:90 (初学一级) | 2012-11-05 09:58
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册