CSV via ASP on a Secure Server

Trying to create a CVS file with ASP works beautifully except when it is on a secure site “https://” and trying to download with IE. All other browsers work well, using “http://” works well. But most people use IE and there is sensitive data so it needs the secure connection.

I get this error
Internet Explorer cannot download ExportReport.asp from Doman.Name.com.
Internet Explorer was not able to open this internet site. The requested site is either unavailable or cannot be found. Please thy again later.

The offending code is
Response.ContentType="application/CSV"

I have tried
Response.ContentType="application/vnd.ms-excel"
With the same result

Also tried but
Response.ContentType="application/octet-stream"
It just opens the results as a page and not in a spreadsheet
cccsatlitAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cccsatlitAuthor Commented:
Also get the same error when the url for the ExportReport.asp is typed directly into the address bar (with both http:// and https://)
0
rdivilbissCommented:
When you set the response mime type to something the user's browser has a mapping for, the browser will try to pass the stream to the application for which there is a matching mime type.

In this case you want a file to be downloaded, so you want to tell the browser it is receiving   a download.  So you tell the browser what the disposition should be rather than letting it decide.

So after your

Response.ContentType="application/CSV"
Response.AddHeader "Content-Disposition","attachment; filename=" & "myFile.csv"

That should force the download dialog.

Regards
Rod
0
cccsatlitAuthor Commented:
I have already tried the attachment in both the ContentType and AddHeader always the same result.
Also the dialog box does open. I just get the error right after, not even given a chance to select save or open.
0
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

rdivilbissCommented:
That clarifies the problem, yet it doesn't bring to mind any solution.  Sorry.

Is it possible for you to paste more code.  If you are getting the attachment save dialoge opening and then are getting an error, it could be something before or after what you've posted.
0
cccsatlitAuthor Commented:
crlf = chr(13) & chr(10)
dlim = ","
CsvOut = ""
bdate=Request("bdate")
edate=Request("edate")
rtype=Request("rtype")
firm_code=session("firm_code")
Select Case "all"
      Case "all"
            All_Report()
            Response.ContentType="application/CSV;"
            Response.AddHeader "Content-Disposition", "attachment; filename=AllReport.csv;"
'a few more cases with the same Structure
End Select
Response.Write(CsvOut)

All_Report builds the CvsOut string
the ContentType has had many different spots from the absolute beginning to its current spot right before the write.
0
cccsatlitAuthor Commented:
Also have this to (missed it earlier because of its location)
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
0
rdivilbissCommented:
This works...

<%
Dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")
 
'Open a stream
objStream.Type = 2 ' adTypeText
objStream.Open
objStream.LoadFromFile Server.MapPath("/ee/test.csv")
objStream.Charset = "iso-8859-1"


Response.AddHeader "Content-Disposition","attachment; filename=test.csv"
objStream.position=2
Response.write objStream.ReadText
objStream.Flush
objStream.Close
%>
0
rdivilbissCommented:
This also works.

<%
Dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")
 
'Open a stream
objStream.Type = 2 ' adTypeText
objStream.Open
objStream.Charset = "iso-8859-1"
objStream.WriteText "First,Last", 1
objStream.WriteText "John,Public", 1
objStream.WriteText "John,Wayne", 1
objStream.WriteText "John,Paul", 1


Response.AddHeader "Content-Disposition","attachment; filename=test.csv"
' point the stream to the begining or you get no output
objStream.Position=0
Response.write objStream.ReadText
objStream.Flush
objStream.Close
%>

Bottom line, it is an IE bug, your original code would work in FireFox and Opera
0
cccsatlitAuthor Commented:
it works but it opens it up in the browser
i get the same result with
Response.ContentType="application/octet-stream"
i am sorry it seems that i only implied it earlier instead of stating it out right i want it to open excel or associated program.
(but the way it is looking right now i may not git it)
0
rdivilbissCommented:
http://www.rodsdot.com/ee/streamCSV.asp

Should allow you to open in Excel in the browser or save the file.

0
OliWarnerCommented:
In FFox that just asks me to save it. Same in IE7. I've got Office and OpenOffice installed but notepad seems to be the default for CSV here.
0
rdivilbissCommented:
Obviously if Excel isn't installed and associated with the browsers csv MIME type then it should open in another program.  Thanks for checking Oli.
0
cccsatlitAuthor Commented:
With the first one the file would have to be created all ready correct?
With the second one it may be a local setting I do get the dialog box but it then opens in the browser (it could be a company setting as it does that in both ie and ff)
(Maybe I did something wrong in my test, because yours worked well. Witch method did you use?)
But that doesn't matter I found it. Thanks to your statement that it is a bug in ie.
I looked on the Microsoft site and found that when the CacheControl is set to no-cache it will throw an error when behind an ssl.
http://support.microsoft.com/kb/323308/en-us
Their fix will fix the browser witch I can’t do but I can remove the CacheControl and now it works
Thanks for your help
I want to get your response to my questions so I will leave this open. (For a little bit)
But rdivilbiss don’t worry you will get the points
0
rdivilbissCommented:
>>With the first one the file would have to be created all ready correct?

objStream.LoadFromFile Server.MapPath("/ee/test.csv") means the file already exists ans we read it into the stream object.

>>With the second one it may be a local setting I do get the dialog box but it then opens in the browser (it could be a company setting as it does that in both ie and ff)

It depends in part on your local settings, e.g. if the CSV mime type is set to be opened by your browser, then yes it would open in the browser.

>>(Maybe I did something wrong in my test, because yours worked well. Witch method did you use?)

<%
Dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")
 
'Open a stream
objStream.Type = 2 ' adTypeText
objStream.Open
' objStream.LoadFromFile Server.MapPath("/ee/test.csv")
objStream.Charset = "iso-8859-1"
objStream.WriteText "First,Last", 1
objStream.WriteText "John,Public", 1
objStream.WriteText "John,Wayne", 1
objStream.WriteText "John,Paul", 1

Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition","attachment; filename=test.csv"
objStream.Position=0
Response.write objStream.ReadText
objStream.Flush
objStream.Close
%>

This is the entire code for the test page I posted that worked well.

NOTE: I used Response.ContentType = "application/vnd.ms-excel" to allow it to be opened in Excel, if loaded on the machine, but

Response.AddHeader "Content-Disposition","attachment; filename=test.csv"
should always force the dialog to allow the browser to choose save or open.

>>I looked on the Microsoft site and found that when the CacheControl is set to no-cache it will throw an error when behind an ssl.  http://support.microsoft.com/kb/323308/en-us

Yes, well you don't really want that set anyway for a download, but I agree its an IE bug, re SSL.

>>Thanks for your help

Your welcome.

>>I want to get your response to my questions so I will leave this open. (For a little bit)

Here they are.
Happy Programming!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cccsatlitAuthor Commented:
thanks again
and have fun
0
rdivilbissCommented:
You're Welcome
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Browsers

From novice to tech pro — start learning today.