Window10 Pro 64bit バージョン 1703 OSビルド 15063.413
Chrome/IE11 VS2013 Community Update5環境において
CrystalReportsにてASP.NETのプログラムを作成しております。
子ウインドウ(A)から、さらにPDF出力用の子ウインドウ(B)をOpenし、
下記の記事を参考に、javascriptによってwindow.open直後に
POSTをするという方法でパラメータを渡して
PDFをストリーム経由で(B)に出力するというプログラムを作成していたところ
Chromeでは問題ないのですが、IE11(11.413.15063.0)では子ウインドウは開くものの
画面が真っ白のまま読み込みが終了してしまいます。
http://qiita.com/tsunet111/items/0167704a65ebc04411f9
※試しにWindows7 32bit のIE11では動作いたしました。
そこで、POSTをやめてGETにてwindow.openをすると
Windows10 IE11で表示されたため、「子ウインドウを開き、POSTする」
というjavascriptの処理の中で対応が必要か?というところで
行き詰っております。
本件CrystalReportsは記載させていただいておりますが
関係ないと判断しております。その根拠としては
・Windows7環境ではChrome/IE11ともに動作確認済みのrptファイルと
PDF出力のロジックをそのまま利用して、window.openの部分を切り替えることによって
現象が発生するかしないかが切り替わることを確認したためです。
2017.06.29 コードを修正しました。
base.aspxをスタートアップとし、baseにあるボタンから、out.aspxでストリーム出力させるサンプルコードです。
<base.aspx> base.aspx.vbファイルは編集無し
lang
1<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="base.aspx.vb" Inherits="WebApplication1.base" %> 2 3<!DOCTYPE html> 4 5<html xmlns="http://www.w3.org/1999/xhtml"> 6<head runat="server"> 7<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 8 <meta http-equiv="content-language" content="ja" /> 9 <meta http-equiv="x-ua-compatible" content="IE=10" /> 10 <meta http-equiv="x-ua-compatible" content="IE=EmulateIE10" /> 11<title>output test</title> 12 <script src="jquery.min.js" type="text/javascript"></script> 13 14 <script type="text/javascript"> 15 $(function () { 16 17 $('#btn_ok').click(function () { 18 19 window.open('out.aspx?type=hist&rpt_hidP=' + 'dummy', '_blank'); 20 21 }); 22 23 $('#btn_dame').click(function () { 24 25 window.open('', 'report'); 26 27 var form = $('<form/>', { 28 id: 'rpt_p', 29 action: 'out.aspx?type=hist', 30 target: 'report', 31 method: 'post' 32 }).append($('<input/>').attr({ 33 type: 'hidden', 34 id: 'rpt_hidP', 35 name: 'rpt_hidP', 36 value: 'dummy' 37 }) 38 ); 39 40 $('body').append(form); 41 42 $('#rpt_p').submit(); 43 $('#rpt_p').remove(); 44 45 form = null; 46 47 }); 48 49 }); 50 </script> 51</head> 52<body> 53 <form id="form1" runat="server"> 54 <div> 55 56 <input type="button" id="btn_ok" value="OKパターン" /> 57 58 <input type="button" id="btn_dame" value="ダメパターン" /> 59 60 </div> 61 </form> 62</body> 63</html> 64
<out.aspx.vb> ※out.aspxは特に編集無し。sample.pdfは1ページの簡単なpdfを使用。
lang
1Imports System 2Imports System.IO 3 4Public Class out 5 Inherits System.Web.UI.Page 6 7 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 8 9 Response.Cache.SetCacheability(HttpCacheability.NoCache) 10 Response.Cache.SetNoStore() 11 12 Dim bLength As Byte() 13 14 'ファイルを開く 15 Dim fs As New System.IO.FileStream(HttpContext.Current.Server.MapPath("pdf/sample.pdf"), System.IO.FileMode.Open, System.IO.FileAccess.Read) 16 17 'ファイルを読み込むバイト型配列を作成する 18 ReDim bLength(fs.Length) 19 'ファイルの内容をすべて読み込む 20 fs.Read(bLength, 0, Convert.ToInt32(bLength.Length)) 21 '閉じる 22 fs.Close() 23 24 Response.ClearHeaders() 25 Response.ClearContent() 26 Response.ContentType = "Application/pdf" 27 28 ' ダイアログ表示 29 Response.AddHeader("content-disposition", "inline; filename=" & System.Web.HttpUtility.UrlEncode("sample.pdf")) 30 31 ' HTTP 出力ストリームに書き込み 32 Response.BinaryWrite(bLength) 33 Response.End() 34 35 End Sub 36 37End Class
OKパターン ボタン 結果
Windows10 64bit Chrome ○ IE11 ○
Windows7 32bit Chrome ○ IE11 ○
ダメパターン ボタン 結果
Windows10 64bit Chrome ○ IE11 ×
Windows7 32bit Chrome ○ IE11 ○
上記のサンプルでも再現することからもrptは関係ないと思われます。
さらに、SurferOnWwwさんからアドバイスいただいたようにFiddlerでキャプチャした結果
OKパターンのキャプチャ
リクエストヘッダー GET /out?type=hist&rpt_hidP=dummy HTTP/1.1
レスポンスヘッダー HTTP/1.1 200 OK
ダメパターンのキャプチャ
リクエストヘッダー POST /out.aspx?type=hist HTTP/1.1
レスポンスヘッダー HTTP/1.1 301 Moved Permanently となり下記のような
HTMLが出力された後 Location: /out?type=hist でリダイレクトされているという違いが明らかになりました。
html
1<html><head><title>Object moved</title></head><body> 2<h2>Object moved to <a href="/out?type=hist">here</a>.</h2> 3</body></html>
Chromeでも同様のキャプチャ結果となりましたが、動作しております。
パラメータが多くなる可能性があるため、できればPOSTで解決したいと
考えております。
対応方法ご存知の方、どうぞよろしくお願いいたします。