Link to home
Start Free TrialLog in
Avatar of cccsatlit
cccsatlit

asked on

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
Avatar of cccsatlit
cccsatlit

ASKER

Also get the same error when the url for the ExportReport.asp is typed directly into the address bar (with both http:// and https://)
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
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.
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.
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.
Also have this to (missed it earlier because of its location)
Response.CacheControl = "no-cache"
Response.AddHeader "Pragma", "no-cache"
Response.Expires = -1
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
%>
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
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)
http://www.rodsdot.com/ee/streamCSV.asp

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

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.
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.
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
ASKER CERTIFIED SOLUTION
Avatar of rdivilbiss
rdivilbiss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks again
and have fun
You're Welcome