在我們的代碼中,可以選擇將元數據導出爲XML文件。代碼如下:發送到Chrome瀏覽器的XML數據不會觸發文件保存對話框
string xml = ToXML(metadatas, files);
context.Response.AddHeader("Content-Type", "application/octet-stream");
context.Response.AddHeader("Content-Disposition", "attachment; filename=video_metadata.xml;");
context.Response.Write(xml);
context.Response.Flush();
context.Response.End();
這在Firefox中運行得很好。他們點擊按鈕並提示保存xml文件。但是,在Chrome中,沒有保存文件提示。使用fiddler,我可以看到xml數據全都在響應中,它的狀態碼爲200.我的Web服務器上沒有顯示錯誤,客戶端也沒有顯示錯誤。它只是無法將發回的數據識別爲保存到文件中的內容。
任何幫助將不勝感激。在相同的Web服務器,我們能夠成功地與頭導出CSV文件,例如:
context.Response.AddHeader("Content-Type", "application/vnd.ms-excel");
context.Response.AddHeader("Content-Disposition", "attachment; filename=AssetList.csv;");
編輯:我想兩者text/xml
和application/xml
,但遺憾的是沒有解決我的問題。
對於「Content-Disposition」標題+1,它創建了一個在瀏覽器中顯示的Excel XML文件。 – Niloct