简体   繁体   中英

Html Header: Open file instead of download it

I have this code in one asp page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Response.AppendHeader("content-disposition", "attachment; filename=PublicKeyCertificate.cer")
    Response.ContentType = "application/x-x509-ca-cert"
    Response.BinaryWrite(Session("cerbytes"))
    Response.End()
End Sub

This code download a .cer file. Instead of download it, is there any way to open it? When you set content-type to application/pdf, most browsers, open the pdf in a new tab. Can i do the same with cer files?

You have:

Response.AppendHeader("content-disposition", "attachment; filename=PublicKeyCertificate.cer")

From the spec :

If the disposition type matches "attachment" (case-insensitively), this indicates that the recipient should prompt the user to save the response locally, rather than process it normally (as per its media type).

On the other hand, if it matches "inline" (case-insensitively), this implies default processing. Therefore, the disposition type "inline" is only useful when it is augmented with additional parameters, such as the filename (see below).

You need to set the the content disposition to inline not attachment .

The browser will then handle it using its native handling. In many cases this will open it in the appropriate preference window (for browsers with internal certificate handling) or the system tool for managing certs (for browsers which hook into the OS for certificate handling).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM