1

我将为用户设置下载,但是当我使用此代码时:

Response.Clear();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + FileName + ".pdf");
Response.WriteFile(Server.MapPath(@"Resumes\" + FileName + ".pdf"));
Response.End();

此错误将显示:

IDM 错误

当我使用这段代码时:

string filename = FileName + ".pdf";
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename);
string aaa = Server.MapPath("~/Resumes/" + filename);
Response.TransmitFile(Server.MapPath("~/Resumes/" + filename));
Response.End();

此错误将显示:

在此处输入图像描述

当我尝试使用浏览器下载文件时,它完全下载没有任何错误,但 IDM 显示这些错误!!!

我正在使用 asp.net 4.5 和 IIS 8

4

1 回答 1

1

I tried this code, it seems that it acts good. but I didn't saw this code anywhere in any website for file download, so I am not sure I doing right. anyway it is working!!!

Response.RedirectPermanent("http://MySite.com/Resumes/" + FileName + ".pdf");
于 2013-10-02T15:59:28.360 回答