0

リンクをクリックしてドキュメントをダウンロードするときに「名前を付けて保存」ポップアップを強制する「ダミー」ページがあります。

そのサイトへのリクエストは 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�

次の 785600 文字についても同様

4

2 に答える 2

1

私は似たようなことをしていますが、それは私にとってはうまくいきます:

Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.TransmitFile(Server.MapPath(FilePath));
Response.End();
于 2010-09-14T14:04:57.103 に答える
1

私はあなたがこのようなことをすることができると思います

Response.ContentType = "Application/pdf";

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

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

Response.End();

これは私が行ったことであり、Rick Strahl のブログのおかげです。個人的には、MIMEタイプを使用してプログラムでコンテンツタイプを決定し、コードがPDFに固有のものではないようにしますが、それは私だけです:)

于 2010-09-14T13:24:22.537 に答える