IE的MHT文件的BinaryWrite不被视为MHT [英] BinaryWrite of MHT file is not treated as MHT by IE

查看:145
本文介绍了IE的MHT文件的BinaryWrite不被视为MHT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个嵌入图像的MHTML文件。 MHTML在服务器上生成,然后我通常使用BinaryWrite传送文件。转换为ASCII并将文件写入磁盘并使用Response.WriteFile后,我也尝试了Server.Transfer,Response.Write。在任何这些情况下,生成的文件都不会(看起来)被视为mht文件。为了设置图像,我尝试了Content-ID和Content-Location。在IE8中查看时,图像URL显示为 cid:example1 。保存到磁盘后打开文件时,它显示为 mhtml:file:// C:\Documents Settings \benjynito \ !Desktop\output634172401776447258.mht CID:例1 。或者在使用其中一种方法进行浏览时,您可以获得 mhttp://...output123.mht!cid:example1

I have an MHTML file which has embedded images. The MHTML is generated on the server and then I will typically deliver the file using a BinaryWrite. I've also tried Server.Transfer, Response.Write after converting to ASCII and writing the file to disk and using a Response.WriteFile. In any of these cases the resulting file is not (it appears) treated as an mht file. For setting the image, I've tried Content-ID and Content-Location. The image URL shows up as cid:example1 when viewed in IE8. When opening up the file after saving to disk it shows up as mhtml:file://C:\Documents and Settings\benjynito\Desktop\output634172401776447258.mht!cid:example1. Or while browsing with one of the methods that work you get mhttp://...output123.mht!cid:example1.

Output.MimeType是message / rfc822。我也尝试过application / octet-stream和multipart / related。

The Output.MimeType is message/rfc822. I've also tried application/octet-stream and multipart/related.

将文件写入磁盘并使用Response.Redirect工作。使用直接URL访问文件有效。将文件保存到磁盘然后打开文件可以正常工作。

Writing the file to disk and using a Response.Redirect works. Accessing the file with a direct URL works. Saving the file to disk and then opening the file works.

似乎IE假定请求的HTML结果而不是解密新的内容类型。但你可以为动态样式表,脚本等做这样的事情......所以我真的不相信。我看不出任何明显的差异。我刚试过,BinaryWrite在Opera中运行良好。

It seems IE is assuming an HTML result to the request and not deciphering the new content type. But you can do things like this for dynamic style sheets, scripts, etc... so I don't really believe that. I couldn't see any glaring differences. I just tried and the BinaryWrite works fine in Opera.

如果我绝对不得不担心写入临时目录然后重定向到文件我会。我只是希望避免清理临时文件。我想做的不可能吗?编写该文件的示例如下。

If I absolutely have to worry about writing to a temporary directory and then redirecting to the file I will. I was just hoping to avoid having to clean up the temporary files. Is what I want to do not possible? An example of writing the file is below.

提前致谢!

if (response != null && response.Output != null)
{
    Response.Clear();
    Response.AddHeader("Content-Type", response.Output.MimeType);
    Response.AddHeader("Content-Disposition", "attachment;filename=output" + DateTime.UtcNow.Ticks.ToString(CultureInfo.InvariantCulture) + "." + response.Output.Extension);

    // Response.Write( System.Text.Encoding.ASCII.GetString(response.Output.Bytes));
    Response.BinaryWrite(response.Output.Bytes);

    //Response.Clear();
    //Server.Transfer("/ISV/Forms/Test/output634172397522707394.mht");

    //Response.Clear();
    //Response.WriteFile( Server.MapPath("/ISV/Forms/Test/output634172397522707394.mht"));

    Response.Flush();
    Response.End();
}


推荐答案

我不认为你Content-Type和Content-Disposition标头是正确的。当您将MHTML作为静态文件下载时,请使用Fiddler查看它们的设置。

I don't think your Content-Type and Content-Disposition headers are correct. Use Fiddler to see what they're set to when you download MHTML as a static file.

尝试一种类型的多部分/相关和内联的处置。 一些证据表明这种组合有效。

Try a type of multipart/related and a disposition of inline. There's some evidence that this combination works.

这篇关于IE的MHT文件的BinaryWrite不被视为MHT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆