如何解决“从服务器收到的重复标头”下载文件时出错 [英] How to resolve "Duplicate headers received from the server" error when download a file
问题描述
嗨朋友们,
在我的网络应用程序中,用户只需在.pdf,.rtf,.doc,.docx格式上传他们的简历即可申请职业部分。
我已将数据库和文件中的文件路径保存在Application文件夹中。
然后我显示在管理部分的网格视图中应用用户的所有信息,我也在网格中给出了一个下载按钮,在gridview Rowcommand事件我有以下代码用于恢复文件下载...
Hi friends,
In my web application User apply in Careers section with uploading their resume in .pdf, .rtf, .doc, .docx formats only.
I have saved the file path in database and file in Application folder.
Then I have displayed all information of applied user in gridview in Admin section, I have given a download button in grid also, At gridview Rowcommand event i have following code for resume file download...
protected void gdUser_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "downLoad")
{
DataTable dt = new DataTable();
Int32 id = Convert.ToInt32(e.CommandArgument);
p.Admin_Flag = 8;
p.Id = id;
p.DateFrom_Sorting = System.DateTime.Now;
p.DateTo_Sorting = System.DateTime.Now;
dt = b.Job_Applied_GridShow(p);
if (dt.Rows.Count > 0)
{
string filepath = "~/" + dt.Rows[0]["file_path"].ToString();
//.......................................................
string path = Server.MapPath(filepath);
//get physical file path from server
string name = Path.GetFileName(path);
//get file name
string ext = Path.GetExtension(path);
//get file extension
string type = "";
// set known types based on file extension
if (ext != null)
{
switch (ext.ToLower())
{
// case ".htm":
// case ".html":
// type = "text/HTML";
// break;
// case ".txt":
// type = "text/plain";
// break;
// case ".GIF":
// type = "image/GIF";
// break;
case ".pdf":
type = "Application/pdf";
break;
case ".doc":
type = "Application/msword";
break;
case ".docx":
type = "Application/msword";
break;
case ".rtf":
type = "Application/msword";
break;
Default:
type = "";
break;
}
}
Response.AppendHeader("content-disposition", "attachment; filename=" + name);
if (type != "")
{
Response.ContentType = type;
Response.WriteFile(path);
Response.End(); //give POP to user for file downlaod
}
}
}
}
文件已下载,但在某些情况下,chrome会出现错误信息从服务器收到的重复标题和文件无法下载。
请帮助我....
谢谢
File is downloaded but in some case chrome gives an error like "Duplicate headers received from the server" and file can't be download.
Please help me....
Thanks
推荐答案
请参阅 - 从服务器收到的重复标题 [ ^ ]。
遵循解决方案。
Refer - Duplicate headers received from server[^].
Follow the solution.
尝试添加Response.Clear()
Try adding a Response.Clear()
Response.Clear();
Response.AppendHeader("content-disposition", "attachment; filename=" + name);
这篇关于如何解决“从服务器收到的重复标头”下载文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!