Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用于在ASP.NET中下载的文件_C#_Content Disposition - Fatal编程技术网

C# 用于在ASP.NET中下载的文件

C# 用于在ASP.NET中下载的文件,c#,content-disposition,C#,Content Disposition,我有一个“虚拟”页面,当他们点击链接下载文档时,可以强制弹出“SaveAs” 对该站点的请求是ajax,该站点被调用。 我可以确定它有所有正确的参数,但当涉及到这一部分时,什么都没有发生 var filepath = Request["filepath"]; //Set the appropriate ContentType. Response.ContentType = "Application/pdf"; //Get the physical path to the file. strin

我有一个“虚拟”页面,当他们点击链接下载文档时,可以强制弹出“SaveAs”

对该站点的请求是ajax,该站点被调用。 我可以确定它有所有正确的参数,但当涉及到这一部分时,什么都没有发生

var filepath = Request["filepath"];

//Set the appropriate ContentType.
Response.ContentType = "Application/pdf";
//Get the physical path to the file.
string FilePath = MapPath(filepath);
Response.AppendHeader("content-disposition", "attachment; filename=" + FilePath);
//Write the file directly to the HTTP content output stream.
Response.WriteFile(FilePath);
esponse.End();
对于firebug,如果我查看标题,我可以看到我尝试响应某些内容

Server ASP.NET Development Server/10.0.0.0
Date Tue, 14 Sep 2010 12:51:02 GMT
X-AspNet-Version 4.0.30319
Content-Disposition attachment; filename=D:\APPLICATIONS\InfoomFilm.pdf
Cache-Control private
Content-Type Application/pdf
Content-Length 785693
Connection Close
但如果我看一下反应,它看起来像

%PDF-1.3
%���������
4 0 obj
<< /Length 5 0 R /Filter /FlateDecode >>
stream
x��ْ��u���)pي k��w�,��($þp袇,rz�lR���z�~��+8�/��$�Ld�P�,rȑ"�'��%d���s�ע,�mi��}9�}Wt�n[C[m���P�WqW|��CU<�����s{m[���f����a�
%PDF-1.3
%���������
40 obj
>
流动

x��ْ��U���)pيk��W�,��($p)袇,rz�lR���Z�~��+8.�/��$�Ld�P�,rȑ”�'��%D���s�ע,�惯性矩��}9�}Wt�n[C[m���P�WqW|��我想你可以这样做

Response.ContentType = "Application/pdf";

Response.AppendHeader("content-disposition", "attachment; filename=" + FilePath);

Response.TransmitFile( Server.MapPath(filepath) );

Response.End();

这可能会起作用-这是我所做的,多亏了Rick Strahl的博客。我个人会使用MIME类型通过编程确定内容类型,这样代码就不会指定为PDF,但这只是我:)

我做了类似的事情,它对我有效:

Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.TransmitFile(Server.MapPath(FilePath));
Response.End();