?
Solved

BinaryWrite over SSL not working in IE

Posted on 2008-11-06
4
Medium Priority
?
1,170 Views
Last Modified: 2012-06-27
I am trying to have a page that offers a logged in user a text document for download. The text documents are in a password protected folder so the page would log in with the appropriate user to access the folder and then uses a binarywrite to serve up the text document. My code works perfectly in IE in a non secure environment but when I try to do it over SSL, I get the following error when I try to download the text document.

"Internet exlporer cannot download download.asp from secure.pageconcepts.com.

Internet explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later."

It also seems to work in netscape. I really need to be able to offer password protected documents to logged in users so any help would be very much appreciated.

Here is the code I am using:

dim oSecurity
Set oSecurity = Server.CreateObject("SoftArtisans.FileManager")
oSecurity.LogonUser "XXXXXXX", "username", "password"

openDB()
openFrontDB(clientID)

Dim      objStream
Dim      strDownloadFilename
Dim                strFile
dim                homeDirectory
Dim                strFileType
Dim                contentType

homeDirectory = "theDirectory"

Response.Buffer = True
Dim strFilePath, strFileSize, strFileName

Const adTypeBinary = 1

strFile = Request.QueryString("file")
strDownloadFilename = Request.QueryString("file")

' get full path of specified file
strFilePath = "C:\inetpub\wwwroot\" &  homeDirectory & "\MoM\" & strFile
strFileName = strDownloadFilename

Response.Clear

Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath

strFileType = lcase(Right(strFileName, 4))

' Feel Free to Add Your Own Content-Types Here
Select Case strFileType
Case ".asf"
ContentType = "video/x-ms-asf"
Case ".avi"
ContentType = "video/avi"
Case ".doc"
ContentType = "application/msword"
Case ".zip"
ContentType = "application/zip"
Case ".xls"
ContentType = "application/vnd.ms-excel"
Case ".gif"
ContentType = "image/gif"
Case ".jpg", "jpeg"
ContentType = "image/jpeg"
Case ".wav"
ContentType = "audio/wav"
Case ".mp3"
ContentType = "audio/mpeg3"
Case ".mpg", "mpeg"
ContentType = "video/mpeg"
Case ".rtf"
ContentType = "application/rtf"
Case ".htm", "html"
ContentType = "text/html"
Case ".asp"
ContentType = "text/asp"
Case Else
'Handle All Other Files
ContentType = "application/octet-stream"
End Select


Response.AddHeader "Content-Disposition", "attachment; filename= " & strFileName
Response.AddHeader "Content-Length", strFileSize
Response.Charset = "UTF-8"
Response.ContentType = ContentType

Response.BinaryWrite objStream.Read
Response.Flush

objStream.Close
Set objStream = Nothing
0
Comment
Question by:DEWebWorks
  • 3
4 Comments
 
LVL 4

Accepted Solution

by:
Chizl earned 2000 total points
ID: 22933680
Try this..   I wrote this a very long time ago, however, I dont know if the XML object can load files from the HD..  Iv'e always used it over the web.

http://www.karland.com/code/asp/files/ASP-BinaryWrite.txt
0
 

Author Comment

by:DEWebWorks
ID: 22934150
It did not work for me. I am getting an access denied error on the objXML.send line. Thanks for the possible solution though.
0
 
LVL 4

Expert Comment

by:Chizl
ID: 23892714
I wrote something recently after I posted this that pulled files from the HD and sent them down to the client using ADO Stream and the XML Object..   it did it in chunks, which worked out nicely and it was all over SSL.   When I get back to the office, I'll look it up and post a link to my solution..
0
 
LVL 4

Expert Comment

by:Chizl
ID: 23911342
Here is what I did..    sFile is the path to the file, via directory, not http.  

However I found a problem with this way and no real way around it..  
objStream.LoadFromFile(sFile)

This will load the file in full before moving to the next step, so if the file is 100MB in size, it's slow.  I searched for a while and there doesnt seem to be a way to pick up the file in chuncks unless I move to .NET.
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
If objFSO.FileExists(sFile) Then
	Set objFile = objFSO.GetFile(sFile)
	Dim iFileSize
	iFileSize = objFile.Size
  Response.AddHeader "Content-Disposition", "attachment; filename=" & objFile.Name
	Response.AddHeader "Content-Length", iFileSize
	Response.ContentType = "application/octet-stream"
	Set objStream = Server.CreateObject("ADODB.Stream")
	objStream.Open
 
	'-- set as binary
	objStream.Type = adTypeBinary
	'-- load into the stream the file
	objStream.LoadFromFile(sFile)
 
	Dim iChunkSize, iLeft
	iChunkSize = 51200	'-- 50KB
	iLeft = iFileSize
 
	Do While Not objStream.EOS Or Not Response.IsClientConnected
		'-- send the stream in the response
		If iChunkSize > iLeft Then iChunkSize = iLeft
		Response.BinaryWrite(objStream.Read(iChunkSize))
		Response.Flush
		iLeft = iLeft - iChunkSize
	Loop
 
	objStream.Close
	Set objStream = Nothing
	Set objFile = Nothing
Else
	Response.write("File does not exist")
End if

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month16 days, 21 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question