/// <summary> /// page load (postback data is now available) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load( object sender, EventArgs e) { try { if (Session[HttpSessionStateVariables.RemoteSession.ToString()] == null) { throw new NullReferenceException(); } _remoteSession = (RemoteSession)Session[HttpSessionStateVariables.RemoteSession.ToString()]; // retrieve the pdf file if (!string.IsNullOrEmpty(Request["name"])) { try { var fileStream = _printerServiceClient.GetPdfFile(_remoteSession.Id, Request["name"]); // CAUTION! IE/Edge appears to have issues with inline documents // for instance, it loads twice "application/pdf" documents (https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/6734131/), // which is a problem because the document is deleted on retrieval to enforce security (the second request will thus fail) // the idea behind inline content was to open the pdf in a new tab; it works on every browser but IE/Edge :/ // using attachment instead //FileHelper.DownloadFile(Response, fileStream, Request["name"], true, "application/pdf", "inline"); FileHelper.DownloadFile(Response, fileStream, Request["name"], true, "application/pdf"); } catch (ThreadAbortException) { // occurs because the response is ended after sending the pdf } catch (Exception exc) { System.Diagnostics.Trace.TraceError("Failed to download pdf file ({0})", exc); } finally { // remove the pdf file _printerServiceClient.DeletePdfFile(_remoteSession.Id, Request["name"]); } } } catch (ThreadAbortException) { // occurs because the response is ended after deleting the pdf } catch (Exception exc) { System.Diagnostics.Trace.TraceError("Failed to retrieve the active remote session ({0})", exc); } }
/// <summary> /// page load (postback data is now available) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load( object sender, EventArgs e) { try { if (Session[HttpSessionStateVariables.RemoteSession.ToString()] == null) { throw new NullReferenceException(); } _remoteSession = (RemoteSession)Session[HttpSessionStateVariables.RemoteSession.ToString()]; // retrieve the pdf file if (!string.IsNullOrEmpty(Request["name"])) { try { var fileStream = _printerServiceClient.GetPdfFile(_remoteSession.Id, Request["name"]); FileHelper.DownloadFile(Response, fileStream, Request["name"], true, "application/pdf", Request["disposition"]); } catch (ThreadAbortException) { // occurs because the response is ended after sending the pdf } catch (Exception exc) { System.Diagnostics.Trace.TraceError("Failed to download pdf file ({0})", exc); } finally { // remove the pdf file _printerServiceClient.DeletePdfFile(_remoteSession.Id, Request["name"]); } } } catch (ThreadAbortException) { // occurs because the response is ended after deleting the pdf } catch (Exception exc) { System.Diagnostics.Trace.TraceError("Failed to retrieve the active remote session ({0})", exc); } }