IE11,从页面上下载文件,save时提示下载失败,该怎么解决
IE11,从页面上下载文件,save时提示下载失败
用这个方法直接从页面上下载,通过IE11浏览,点击下载,会弹出如下图所示的下载提示框,

点击保存后,就会报这个错误:

失败的这个文件360kb,按理说这么小不至于的啊,问题出在IE11(IE10发现也会失败)的设置上吗?
如果通过IE8就能行,IE8的下载是个弹出窗口,然后点击保存就成功了。

代码没有捕捉到异常,即使是save失败的时候代码也没有抛出异常,我用记log的方式调查过。
session的过期时间采用的是20min,下载失败的情况也没有超过20min。
有人遇到过这种情况吗?求指教啊····多谢!
------解决思路----------------------
下载浏览器补丁
------解决思路----------------------
这个文件有多大啊?有一个header属性叫长连接。查一下Keep-Alive吧。
------解决思路----------------------
只是单纯的下载么 ?
没有操作word文件吧
------解决思路----------------------
单纯的下载,ASP.NET 以文件流方式下载,IE8没任何问题。
IE11 有时成功 ,有时失败。
失败提示 “无法下载。。。”
------解决思路----------------------
换其他方式 也这个问题,IE11有时成功,有时失败。
WIN2012的IE11 和 WIN7的IE11都有该问题。
------解决思路----------------------
如何下载文件
//加载检索服务器中的文件名
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Name", typeof(string)));
string serverPath = Server.MapPath("File");
DirectoryInfo dir = new DirectoryInfo(serverPath);
foreach (FileInfo fileName in dir.GetFiles())
{
DataRow dr = dt.NewRow();
dr[0] = fileName;
dt.Rows.Add(dr);
}
ListBox1.DataSource = dt;
ListBox1.DataTextField = "Name";
ListBox1.DataValueField = "Name";
ListBox1.DataBind();
}
}//codego.net/tags/11/1/
//选中索引保存到Session变量中
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Session["txt"] = ListBox1.SelectedValue.ToString();
}
//完成下载事件
protected void LinkButton1_Click(object sender, EventArgs e)
{
if (Session["txt"] != "")
{
string path = Server.MapPath("File/") + Session["txt"].ToString();
FileInfo fi = new FileInfo(path);
if (fi.Exists)
{
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode( fi.Name));
Response.WriteFile(fi.FullName);
}
}
}
------解决思路----------------------
如果下载出错后,按retry能正常下载的话
HttpContext.Current.Response.Close();
改成HttpContext.Current.ApplicationInstance.CompleteRequest(); 试试
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/vnd.ms-pdf";
HttpContext.Current.Response.AddHeader("Content-disposition", "attachment; filename=" + fileName + ".pdf");
HttpContext.Current.Response.BinaryWrite(bytes);
HttpContext.Current.Response.Flush();
HttpContext.Current.Response.Close();
用这个方法直接从页面上下载,通过IE11浏览,点击下载,会弹出如下图所示的下载提示框,
点击保存后,就会报这个错误:
失败的这个文件360kb,按理说这么小不至于的啊,问题出在IE11(IE10发现也会失败)的设置上吗?
如果通过IE8就能行,IE8的下载是个弹出窗口,然后点击保存就成功了。
代码没有捕捉到异常,即使是save失败的时候代码也没有抛出异常,我用记log的方式调查过。
session的过期时间采用的是20min,下载失败的情况也没有超过20min。
有人遇到过这种情况吗?求指教啊····多谢!
------解决思路----------------------
下载浏览器补丁
------解决思路----------------------
这个文件有多大啊?有一个header属性叫长连接。查一下Keep-Alive吧。
------解决思路----------------------
只是单纯的下载么 ?
没有操作word文件吧
------解决思路----------------------
单纯的下载,ASP.NET 以文件流方式下载,IE8没任何问题。
IE11 有时成功 ,有时失败。
失败提示 “无法下载。。。”
------解决思路----------------------
换其他方式 也这个问题,IE11有时成功,有时失败。
WIN2012的IE11 和 WIN7的IE11都有该问题。
try
{
//开始下载 附件
#region
using (EA.Common.IdentityScope c = new EA.Common.IdentityScope(sUsername, sDomain, sPassword))
{
string filename = path + head.AttachmentsPath;
FileStream fs = new FileStream(filename, FileMode.Open);
Stream sw = Response.OutputStream;
Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(head.AttachmentsName));
byte[] buf = new byte[256];
int cnt = fs.Read(buf, 0, 256);
while (cnt > 0)
{
sw.Write(buf, 0, cnt);
Response.Flush();
cnt = fs.Read(buf, 0, 256);
}
sw.Close();
fs.Close();
sw.Dispose();
fs.Dispose();
}
Response.Close();
//Response.End();
#endregion
}
------解决思路----------------------
如何下载文件
//加载检索服务器中的文件名
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Name", typeof(string)));
string serverPath = Server.MapPath("File");
DirectoryInfo dir = new DirectoryInfo(serverPath);
foreach (FileInfo fileName in dir.GetFiles())
{
DataRow dr = dt.NewRow();
dr[0] = fileName;
dt.Rows.Add(dr);
}
ListBox1.DataSource = dt;
ListBox1.DataTextField = "Name";
ListBox1.DataValueField = "Name";
ListBox1.DataBind();
}
}//codego.net/tags/11/1/
//选中索引保存到Session变量中
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Session["txt"] = ListBox1.SelectedValue.ToString();
}
//完成下载事件
protected void LinkButton1_Click(object sender, EventArgs e)
{
if (Session["txt"] != "")
{
string path = Server.MapPath("File/") + Session["txt"].ToString();
FileInfo fi = new FileInfo(path);
if (fi.Exists)
{
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode( fi.Name));
Response.WriteFile(fi.FullName);
}
}
}
------解决思路----------------------
如果下载出错后,按retry能正常下载的话
HttpContext.Current.Response.Close();
改成HttpContext.Current.ApplicationInstance.CompleteRequest(); 试试