Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Downloading file in SSL siteDownloading file in SSL site
Previous
 
Next
New Post
8/28/2007 6:59 PM
 

Hello,

I am having all sorts of trouble getting by simple download code to work in my production site which uses SSL. I am not doing anything too fancy and the code works perfeclty fine if I log into the production site without SSL.

...set up the byteArray and sFileName...

With Page.Response
Try
.Clear()
.Charset = "iso-8859-1"
.Cache.SetCacheability(HttpCacheability.NoCache)
'.ContentType = "text/csv"  '--- Note that if I use this I dont even get a download dialog, the code immediately tries to download default.aspx??
.ContentType = "application/x-zip-compressed"  ' ---- Note that this will at least give me a download dialog
.AddHeader("content-disposition", "attachment; filename=" & sFilename)
.AddHeader("Content-Length", byteArray.Length.ToString())
.AddHeader("Accept-Ranges", "bytes")
.AddHeader("Accept-Header", byteArray.Length.ToString())
.OutputStream.Write(byteArray, 0, byteArray.Length)
.Flush()
HttpContext.Current.ApplicationInstance.CompleteRequest()
Catch ex As Exception
HttpContext.Current.ApplicationInstance.CompleteRequest()
.StatusCode = 404
.StatusDescription = "Requested resource not found"
End Try
End With

I have also gotten download to work in DNN by redirectly to another .aspx page. When I use the above code from within my code-behind is a open|save|cancel dialog that indicates that I am about to download default_aspx (.ContentType = "application/x-zip-compressed") and then if I click save the download fails and indicates that default.aspx is not available. If I try to open then the page opens up just fine and displays the contents of the .csv. Btw I have set the mimetypes in the compression.config (remember this works fine when not using SSL). Is there a problem with the context object or the headers? Any advice would be greatly appreciated.

Thanks!

 
New Post
8/29/2007 2:19 PM
 

I solved my own mystery of the SSL Download Disaster: Add .ClearContents() and .ClearHeaders() and Remove .Clear() also ensure that you do not use .End() as this will cause a threading error which can be handled with a Try...Catch, but better to use HttpContext.Current.ApplicationInstance.CompleteRequest() which does not cause the same threading error.

This code is all you need to get around the problem I would image any DNN 4.4+ developer will have when doing Save type downloads (with compression on) under SSL: Note that if you use the HttpSetCacheability then set it to Public only. Below is all the code you need to make it work in most cases. Below that I put my complete code which will optimize the process in most cases.

With Page.Response
.ClearContent()
.ClearHeaders()
.ContentType = "text/csv" ' "application/ms-excel" '"application/x-zip-compressed"
.AddHeader("content-disposition", "attachment; filename=Test1.csv")
.OutputStream.Write(byteArray, 0, byteArray.Length)
HttpContext.Current.ApplicationInstance.CompleteRequest()
End With

With Page.Response
Try
.ClearContent()
.ClearHeaders()
.Charset = "iso-8859-1"
.Cache.SetCacheability(HttpCacheability.Public)
.ContentType = "text/csv"
.AddHeader("content-disposition", "attachment; filename=Test1.csv") 'sFilename
.Buffer = True
.AddHeader("Content-Length", byteArray.Length.ToString())
.AddHeader("Accept-Ranges", "bytes")
.AddHeader("Accept-Header", byteArray.Length.ToString())
.OutputStream.Write(byteArray, 0, byteArray.Length)
.OutputStream.Flush()
HttpContext.Current.ApplicationInstance.CompleteRequest()
Page.Controls.Clear()
Catch ex As Exception
HttpContext.Current.ApplicationInstance.CompleteRequest()
.StatusCode = 404
.StatusDescription = "Requested resource not found"
End Try
End With

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Downloading file in SSL siteDownloading file in SSL site


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out