私たちのウェブサイトでは、複数のレポートをExcelスプレッドシートとしてダウンロードできます。それをMemoryStreamにコピーし、DocumentFormat.OpenXml.Spreadsheetでテンプレートにデータをプッシュします。次に、ヘッダを設定し、ストリームをレスポンスにコピーする関数にMemoryStreamを渡します。IE9は、.xlsxとしてバイナリBLOBを送信するときにランダムにポップアップするWindowsセキュリティダイアログ
作品は、私はあなたのリモートサーバにログインするように求めるWindowsセキュリティのログインダイアログをランダムにポップアップするが、あなたはIE9(と8、私のQAが教えてくれた)をで公開しています。ダイアログをキャンセルするか、okを押して(資格情報が無視されるように見える)、Excelファイルを期待どおりに取得できます。 (CharlesProxyを使って)クエリを見ると、CharlesProxyを再び無効にするまでログインダイアログが表示されないので、私のdevマシンとサーバーの間のトラフィックに違いがあるかどうかはわかりません。また、Dev/Testサーバーからローカルホストからデバッグを実行しているときにも発生しません。
どのようなヘルプも便利です。問題のコードは次のとおりです。これは、コードの背後にあるサーバー側の関数から呼び出されます。そのため、RespondAsExcelはレスポンスを消去し、xlsxに代入します。
using (MemoryStream excelStream = new MemoryStream())
{
using (FileStream template = new FileStream(Server.MapPath(@"Reports\AlignedTemplateRII.xlsx"), FileMode.Open, FileAccess.Read))
{
Master.CopyStream(template, excelStream);
}
//Logic here to push data into the Memory stream using DocumentFormat.OpenXml.Spreadsheet;
Master.RespondAsExcel(excelStream, pgmName);
}
public void RespondAsExcel(MemoryStream excelStream, string fileName)
{
var contenttype = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.Clear();
Response.ContentType = contenttype;
fileName = Utils.ReplaceWhiteSpaceWithUnderScores(fileName);
Response.AddHeader("content-disposition", "inline;filename=" + fileName);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(excelStream.ToArray());
//If that doesn't work, can try this way:
//excelStream.WriteTo(Response.OutputStream);
Response.End();
}
public void CopyStream(Stream source, Stream destination)
{
byte[] buffer = new byte[32768];
int bytesRead;
do
{
bytesRead = source.Read(buffer, 0, buffer.Length);
destination.Write(buffer, 0, bytesRead);
} while (bytesRead != 0);
}
コンテンツタイプを' application/octet-stream'に設定してみてください。 –
これは動作上の変化はありません。残念ながら – Drogo