回答編集履歴

1

追記追加

2017/06/29 07:34

投稿

退会済みユーザー
test CHANGED
@@ -27,3 +27,269 @@
27
27
 
28
28
 
29
29
  (根本的にやり方を変えないとダメということになりそうな気がします)
30
+
31
+
32
+
33
+ ----- 2017/6/29 16:34 追記 -----
34
+
35
+
36
+
37
+ 下の 2017/06/29 15:48 の私のコメントで「自分の環境と検証に使ったコードその他の情報を回答欄に書いておきます」と書きましたが、それを以下に書いておきます。
38
+
39
+
40
+
41
+ **環境:**
42
+
43
+ Visual Studio Commnuty 2015 Update 3
44
+
45
+ ASP.NET Web Forms(Web サイトプロジェクトとして作成、IIS のサイトに設定)
46
+
47
+ .NET Framework 4.6.1
48
+
49
+ Windows 10 Pro 64-bit, 10.0.14393 ビルド 14393
50
+
51
+ IIS 10.0, CLR v4.0, 64-bit, 統合パイプラインモード
52
+
53
+ IE11 ver. 11.1358.14393.0 更新 ver. 11.0.43 (KB4021558)
54
+
55
+
56
+
57
+ **ソースコード**
58
+
59
+
60
+
61
+ **base.aspx **に該当するもの。コードビハインド形式にせず一体にしています。
62
+
63
+
64
+
65
+ ```
66
+
67
+ <%@ Page Language="C#" %>
68
+
69
+
70
+
71
+ <!DOCTYPE html>
72
+
73
+
74
+
75
+ <script runat="server">
76
+
77
+
78
+
79
+ </script>
80
+
81
+
82
+
83
+ <html xmlns="http://www.w3.org/1999/xhtml">
84
+
85
+ <head runat="server">
86
+
87
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
88
+
89
+ <title></title>
90
+
91
+ <script src="/Scripts/jquery-1.10.2.js"></script>
92
+
93
+ <script type="text/javascript">
94
+
95
+ //<![CDATA[
96
+
97
+ $(function () {
98
+
99
+ $('#btn_ok').click(function () {
100
+
101
+ window.open('0008-out.aspx', '_blank');
102
+
103
+ });
104
+
105
+
106
+
107
+ $('#btn_dame').click(function () {
108
+
109
+ window.open('', 'report');
110
+
111
+
112
+
113
+ var form = $('<form/>', {
114
+
115
+ id: 'rpt_p',
116
+
117
+ action: '0008-out.aspx',
118
+
119
+ target: 'report',
120
+
121
+ method: 'post'
122
+
123
+ });
124
+
125
+
126
+
127
+ $('body').append(form);
128
+
129
+
130
+
131
+ $('#rpt_p').submit();
132
+
133
+ $('#rpt_p').remove();
134
+
135
+ });
136
+
137
+ });
138
+
139
+ //]]>
140
+
141
+ </script>
142
+
143
+ </head>
144
+
145
+ <body>
146
+
147
+ <form id="form1" runat="server">
148
+
149
+ <div>
150
+
151
+ <h1>window.open で開いたウィンドウに pdf をダウンロード</h1>
152
+
153
+ <input type="button" id="btn_ok" value="GET" />
154
+
155
+ <input type="button" id="btn_dame" value="POST" />
156
+
157
+ </div>
158
+
159
+ </form>
160
+
161
+ </body>
162
+
163
+ </html>
164
+
165
+ ```
166
+
167
+
168
+
169
+ **out.aspx.vb** に該当するもの。言語は C# です。(ページの名前は 0008-out.aspx としています)
170
+
171
+
172
+
173
+ ```
174
+
175
+ using System;
176
+
177
+ using System.Collections.Generic;
178
+
179
+ using System.Linq;
180
+
181
+ using System.Web;
182
+
183
+ using System.Web.UI;
184
+
185
+ using System.Web.UI.WebControls;
186
+
187
+
188
+
189
+ public partial class _0008_out : System.Web.UI.Page
190
+
191
+ {
192
+
193
+ protected void Page_Load(object sender, EventArgs e)
194
+
195
+ {
196
+
197
+ Response.Cache.SetCacheability(HttpCacheability.NoCache);
198
+
199
+ Response.Cache.SetNoStore();
200
+
201
+
202
+
203
+ Response.ClearHeaders();
204
+
205
+ Response.ClearContent();
206
+
207
+ Response.ContentType = "Application/pdf";
208
+
209
+ Response.AddHeader("content-disposition", "inline; filename=sample.pdf");
210
+
211
+ string path = Server.MapPath("~/app_data/sample.pdf");
212
+
213
+ Response.TransmitFile(path);
214
+
215
+ Response.End();
216
+
217
+ }
218
+
219
+ }
220
+
221
+ ```
222
+
223
+
224
+
225
+ 上記 base.aspx の[POST]ボタンをクリックしたとき、**Fiddler で見た要求と応答**
226
+
227
+
228
+
229
+ **要求** (コンテンツは設定してないので空です)
230
+
231
+ ```
232
+
233
+ POST http://websiteproject.com/0008-out.aspx HTTP/1.1
234
+
235
+ Accept: text/html, application/xhtml+xml, image/jxr, */*
236
+
237
+ Referer: http://websiteproject.com/0008-AutoPostByScript.aspx
238
+
239
+ Accept-Language: ja
240
+
241
+ User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko
242
+
243
+ Content-Type: application/x-www-form-urlencoded
244
+
245
+ Accept-Encoding: gzip, deflate
246
+
247
+ Content-Length: 0
248
+
249
+ Host: websiteproject.com
250
+
251
+ Connection: Keep-Alive
252
+
253
+ Pragma: no-cache
254
+
255
+ ```
256
+
257
+
258
+
259
+ **応答**
260
+
261
+ ```
262
+
263
+ HTTP/1.1 200 OK
264
+
265
+ Cache-Control: private
266
+
267
+ Content-Type: Application/pdf
268
+
269
+ Server: Microsoft-IIS/10.0
270
+
271
+ content-disposition: inline; filename=sample.pdf
272
+
273
+ X-AspNet-Version: 4.0.30319
274
+
275
+ X-Powered-By: ASP.NET
276
+
277
+ Date: Thu, 29 Jun 2017 07:12:49 GMT
278
+
279
+ Content-Length: 73552
280
+
281
+
282
+
283
+ %PDF-1.4
284
+
285
+ %äüöß
286
+
287
+ 2 0 obj
288
+
289
+ <</Length 3 0 R/Filter/FlateDecode>>
290
+
291
+ stream
292
+
293
+ ・・・以下省略・・・
294
+
295
+ ```