Hi I have a report that is generated by a logged in user using the ExpertPDF htmltopdf On the live website after the report is written to the response as a binary file the Session state seems to get lost and the user has to log back in. However on my dev machine using VS2010 and its inbuilt server the session state seems to be maintained fine. Any ideas ? See code below to see how the file is sent to the client. Code: public static void CreatePDF(string url, string filename, string title) { PdfConverter pdfConverter = new PdfConverter(); pdfConverter.LicenseKey = HTMLlicenseKey; pdfConverter.PdfDocumentOptions.PdfPageSize = ExpertPdf.HtmlToPdf.PdfPageSize.A4; pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal; pdfConverter.PdfDocumentOptions.ShowHeader = false; pdfConverter.PdfDocumentOptions.ShowFooter = true; pdfConverter.PdfDocumentOptions.LeftMargin = 60; pdfConverter.PdfDocumentOptions.RightMargin = 60; pdfConverter.PdfDocumentOptions.TopMargin = 45; pdfConverter.PdfDocumentOptions.BottomMargin = 35; pdfConverter.PdfDocumentOptions.GenerateSelectablePdf = true; pdfConverter.PdfFooterOptions.FooterTextColor = Color.Black; pdfConverter.PdfHeaderOptions.DrawHeaderLine = false; pdfConverter.PdfFooterOptions.DrawFooterLine = false; pdfConverter.PdfFooterOptions.ShowPageNumber = true; pdfConverter.PdfFooterOptions.PageNumberTextFontSize = 9; pdfConverter.PdfFooterOptions.PageNumberTextColor = Color.FromArgb(46, 69, 155); pdfConverter.PdfFooterOptions.PageNumberingFormatString = "&p;"; pdfConverter.PdfFooterOptions.FooterTextFontSize = 9; pdfConverter.PdfFooterOptions.FooterText = "© 0to10RM"; pdfConverter.PdfFooterOptions.FooterTextColor = Color.FromArgb(46, 69, 155); pdfConverter.PdfFooterOptions.ShowOnFirstPage = false; pdfConverter.AvoidImageBreak = true; StringWriter sw = new StringWriter(); HttpContext.Current.Server.Execute(url, sw); string htmlCodeToConvert = sw.GetStringBuilder().ToString(); MemoryStream report_stream = new MemoryStream(); pdfConverter.SavePdfFromHtmlStringToStream(htmlCodeToConvert, PDFBaseURL, report_stream); string serverPath = HttpContext.Current.Server.MapPath("/library/"); string appendix_path = serverPath + "WorkshopTemplate.pdf"; PDFMerge merger = new PDFMerge(); merger.LicenseKey = MergeLicenseKey; merger.AppendPDFStream(report_stream); merger.AppendPDFFile(appendix_path); byte[] downloadBytes = merger.RenderMergedPDFDocument(); System.Web.HttpResponse response = System.Web.HttpContext.Current.Response; response.Clear(); response.AddHeader("Content-Type", "binary/octet-stream"); response.AddHeader("Content-Disposition", "attachment; filename=" + filename + ".pdf" + "; size=" + downloadBytes.Length.ToString()); response.Flush(); response.BinaryWrite(downloadBytes); response.Flush(); response.End(); }
If you sessions are being lost. You might want to read our knowledge base article on how to enable SQL Server sessions on your web application here: How to enable ASP.NET SQL Server Session on your web application Please note the following: We host each website in its unique application pool/process. To ensure server stability we recycle the application if any of the following conditions are met: 1) More than 20 minutes of idle time (no HTTP request in 20 minutes) 2) The application uses more than 100 MB of memory for our Windows 2003 / IIS 6 and 200 MB of memory for our Windows 2008 / IIS 7 servers. 3) The application uses more than 70% of CPU resources for more than 5 minutes If your web application pool recycles then most likely your sessions will be lost. To avoid this from happening you can use SQL Server sessions in order to retain your sessions even if your application pool recycles.