We help IT Professionals succeed at work.

Opera and Safari not recognizing vCard mimeType for dynamically generated vCards...

sggexchange
sggexchange asked
on
We have a ASHX response handler that dynamically generates .VCF files on the fly and delivers them as ContactLisa.vcf.  Internet Explorer and FireFox recognize the results properly (views the mimetype as text/vCard and saves the file as ContactLisa.vcf).    However both Opera and Safari view the response as "GenerateVCard.ashx" and saved it as such...and ignores the mimeType.  

The content of the saved file is the vCard data so the script is running properly.  

How can we get Opera and Safari to properly recognize the vCard mimetype and save the results as a .VCF file?
Here is the part of the code where we set the mimetype and appropriate headers:
 
context.Response.BufferOutput = true;
context.Response.ContentType = "text/x-vcard";
context.Response.AddHeader("content-disposition", "attachment; filename=ContactLisa.vcf");
context.Response.AddHeader("content-description", "vCard");

Open in new window

Comment
Watch Question

Commented:
Try clearing the headers and the entire buffer before setting the new headers.  It could be that there is something extra there that those browsers do not like.  Can you post the entire HTTP header output of the above code?

   -dZ.

Author

Commented:
Thanks for the advice but clearing the headers did not work....here is what our script is passing back...complete response with headers and content.  Any ideas?  Thanks!

HTTP/1.1 200 OK
Connection: close
Date: Tue, 29 Jan 2008 20:06:04 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
content-disposition: attachment; filename=OrlandoViolinist.vcf
content-description: vCard
Cache-Control: private
Content-Type: text/x-vcard; charset=utf-8

Content-Length: 512

BEGIN:VCARD
VERSION:2.1
N:Ferrigno; Lisa;;;
FN: Lisa Ferrigno
ORG: ;
TITLE:Orlando Violinist
NOTE;ENCODING=QUOTED-PRINTABLE:This is a note associated with this
contact=0D=0A
TEL;WORK;VOICE:(407) 123-4567
TEL;HOME;VOICE:
TEL;CELL;VOICE:
TEL;WORK;FAX:
ADR;WORK:;;P.O. Box 3603;Winter Park;FL 32790;;USA
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:P.O. Box 3603=0D=0AWinter Park, FL
32790 =0D=0AUSA
URL:lfv.sggportfolio.com
URL:lfv.sggportfolio.com
EMAIL;PREF;INTERNET:mkt@sggmail.test
REV:
END:VCARD


Commented:
I just tried the following page, saved as "index.aspx", in Opera and it works as expected:

------ START index.aspx
<%@ Page Language="c#" %>
<%
      HttpContext.Current.Response.BufferOutput = true;
      HttpContext.Current.Response.ContentType = "text/x-vcard";
      HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=Contact.vcf");
      HttpContext.Current.Response.AddHeader("Content-Description", "vCard");
%>
BEGIN:VCARD
VERSION:2.1
N:Ferrigno; Lisa;;;
FN: Lisa Ferrigno
ORG: ;
TITLE:Orlando Violinist
NOTE;ENCODING=QUOTED-PRINTABLE:This is a note associated with this
contact=0D=0A
TEL;WORK;VOICE:(407) 123-4567
TEL;HOME;VOICE:
TEL;CELL;VOICE:
TEL;WORK;FAX:
ADR;WORK:;;P.O. Box 3603;Winter Park;FL 32790;;USA
LABEL;WORK;ENCODING=QUOTED-PRINTABLE:P.O. Box 3603=0D=0AWinter Park, FL
32790 =0D=0AUSA
URL:lfv.sggportfolio.com
URL:lfv.sggportfolio.com
EMAIL;PREF;INTERNET:mkt@sggmail.test
REV:
END:VCARD
------ END


This was using Windows XP, and .NET 2.0.  Can you confirm that the above does not work for you?

    -dZ.

Author

Commented:
Afraid it still doesn't work for us using Opera or Safari.   The content attachment filename "contact.vcf" is not retained and the file still saves as an ASPX page (and opens in Visual Studio).

In FireFox and IE it is fine...as our script was before.  

 In Safari on a Mac (our client has a Mac which is why we are scrambling to make this work), the address book can't recognize the file and says:  No importable cards were found.

Do you have any other ideas?  I appreciate the help!  
Commented:
I haven't tried it on a Mac, but I don't doubt that the problem exists.  It's strange that it doesn't work on Safari and Opera, which are some of the best standards-compliant browsers.  I don't really see *anything* wrong with the output you posted.

Try changing the Content-Type to the generic binary type:  "application/octet-stream".  However, this means that the AddressBook application won't be able to open it automtically.

Try adding this:
<%
      HttpContext.Current.Response.BufferOutput = true;
      HttpContext.Current.Response.ContentType = "text/x-vcard; name="Contact.vcf"";
      HttpContext.Current.Response.AddHeader("Content-Transfer-Encoding", "7bit")
      HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=Contact.vcf");
      HttpContext.Current.Response.AddHeader("Content-Description", "vCard");
%>

Which versions of Safari and Opera are you using anyway?  It could be that they are not set up to support that MIME type.

    -dZ.

Author

Commented:
Thanks for taking a shot at this.  We ended up ditching the dynamic generation part of the vcards in favor of just putting real vcards on the site.  The contact information will probably never change anyway.

Thanks for the help!