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("文件下载时出现错误!"); }
// No cache. context.Response.Cache.SetCacheability(HttpCacheability.NoCache); context.Response.AppendHeader(@"Pragma",@"no-cache");
就是因为no-cache才导致这个问题的,呵呵!
mark
原来是IIS的问题,IIS设置加多了一个head,所以在程序端修改不了,在HTTPS下会有两个head并存