Developer forum

Forum » Development » OrderTemplateExtender file download problem

OrderTemplateExtender file download problem

Gaetan Di Caro
Reply

Hello,

I have coded an OrderTemplateExtender to dynamically generate a zip file and send it to the customer when he adds to basket (as per an image bank feature of our website). The code works very well and the zip file is generated and sent without problem.

However I noticed that after the download, every single page I try to access is blank. It is fixed only by deleting the ASP.NET session cookie, or have the session expire. I tried different ways to end the response but so far I haven't had any success...

Here is my code :

public class OrderTemplateExtender1 : OrderTemplateExtender
{
	public override void ExtendTemplate(Dynamicweb.Rendering.Template template)
	{
		try
		{
			if (base.Order != null
				&& base.Order.OrderLines != null
				&& base.Order.OrderLines.Count > 0
				&& RenderingState == TemplateExtenderRenderingState.Before)
			{
				/* 
					Snip : 
					1) Create a temporary folder
					2) Downloading the images into it
					3) Creating the zip file in another folder
					4) Deleting first temp folder
				*/

				HttpContext.Current.Response.Clear();
				HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment; filename=" + archiveName);
				HttpContext.Current.Response.AppendHeader("Content-Length", zipInfos.Length.ToString());
				HttpContext.Current.Response.AppendHeader("Pragma", "no-cache");
				HttpContext.Current.Response.AppendHeader("Cache-Control", "no-cache");
				HttpContext.Current.Response.ContentType = "application/x-zip-compressed";
				HttpContext.Current.Response.TransmitFile(zipPath);
			}
		}
		catch (Exception ex)
		{
			/* Log */
		}

		HttpContext.Current.Response.End();

		// Tried this instead of Response.End, but same result
		//HttpContext.Current.Response.Flush();
		//HttpContext.Current.Response.SuppressContent = true;
		//HttpContext.Current.ApplicationInstance.CompleteRequest();
	}
}

 

Any idea why ? Thanks a lot !


Replies

 
Gaetan Di Caro
Reply

Ok I managed to solve it. The problem was mainly that my response.end was OUTSIDE of my test which looked for something in the basket before doing anything. I rewrote my code to wrap the test around the try/catch instead of having it inside the try, now it's ok.

 

You must be logged in to post in the forum