クライアントが添付ファイルをダウンロードできるようにしたい。これattachment.AttachmentContent
はファイルからのバイト配列です。ボタンをクリックして添付ファイルをダウンロードすると、以下のコードが実行されます。しかし、次のスクリプトエラーがあります。修正するにはどうすればよいですか?
Uncaught Sys.WebForms.PageRequestManagerParserErrorException: Sys.WebForms.PageRequestManagerParserErrorException: サーバーから受信したメッセージを解析できませんでした。このエラーの一般的な原因は、Response.Write() の呼び出しによって応答が変更された場合、応答フィルター、HttpModules、またはサーバー トレースが有効になっている場合です。詳細: '����JFIF``' 付近で解析中にエラーが発生しました。
Attachment attachment = _attachmentService.GetAttachmentBytesById(int.Parse(e.CommandArgument.ToString()));
Response.Clear();
Response.ClearHeaders();
Response.ContentType = "image/jpeg";
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + "test.jpg" + "\"");
Response.OutputStream.Write(attachment.AttachmentContent, 0, attachment.AttachmentContent.Length);
Response.End();