10

Unable to display .mht file in IE with IIS 7 when the wrong MIME type is sent

 2 years ago
source link: https://www.codesd.com/item/unable-to-display-mht-file-in-ie-with-iis-7-when-the-wrong-mime-type-is-sent.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Unable to display .mht file in IE with IIS 7 when the wrong MIME type is sent

advertisements

We have a page in an ASP.NET site with a link to a .MHT file so when the user clicks on the link he should be able to view the MHT file in the browser.

Problem is that it displays blank and the header that IIS sends with it is like this:

HTTP/1.1 200 OK
Cache-Control: private
Transfer-Encoding: chunked
Content-Type: application/octet-stream
Server: Microsoft-IIS/7.5
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Wed, 18 Jan 2012 18:45:19 GMT

We have on IIS the MIME-type already configured correctly as per default like this:

.mht    message/rfc822

We noticed that if we open the file by the file system in our machine, IE displays it correctly, so the problem is with the header that IIS sends with the file (we assume).

Any idea why IIS is sending this header that prevents us of displaying the MHT file correctly? Any solution?

Thanks a lot!

UPDATE

We think of several workarounds now: see answer by me.

*Thanks everyone!


  1. Use HTTP Handler:

    a) In web.config under system.web add a node similar to:

    <add verb="GET" path="*.mht" type="WebApplication1.Handler1" />
    
    

    b) In Handler's Code Behind, inside ProcessRequest method add this:

    context.Response.ContentType = "message/rfc822";
    context.Response.Write(System.IO.File.ReadAllText(context.Server.MapPath(context.Request.FilePath)));
    
    
  2. Use ISAPI filters to change the Content-Type header before sending it to the client. You will need Windows 7 SDK for Server 2008 R2 or olrder versions of the SDK depending on your target server.

  3. In Global.asax, in one of these events, change the header value of Content-Type:

    a) Application_PreSendRequestContent

    or b) Application_PreSendRequestHeaders

    Cons of this: You will intercept every call.

  4. Use CGI scripting to change the Content-Type header value.

We decided to use HTTP Handler solution.

Regards,

Fabian Fernandez


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK