Skip to main content

Access HttpContext.Session in Services

  • 2 minutes to read

The End-User Web Report Designer processes requests coming from its services using separate HTTP handler modules, which do not provide access to HttpContext.Session (for instance, when executing methods to open and save reports to a custom report storage).

Tip

Refer to the Register Services in the Report Designer document for the complete list of available services.

To enable these services to access values stored in HttpContext.Session, select Required in the drop-down list for the Session State property in the Insert DevExpress Extension Wizard.

report-designer-extension-wizard-session-state

This adds the following code to the Global.asax file at application startup:

void Application_Start(object sender, EventArgs e) {
    DevExpress.XtraReports.Web.WebDocumentViewer.Native.WebDocumentViewerBootstrapper.SessionState = 
        System.Web.SessionState.SessionStateBehavior.Required;

    DevExpress.XtraReports.Web.QueryBuilder.Native.QueryBuilderBootstrapper.SessionState = 
        System.Web.SessionState.SessionStateBehavior.Required;

    DevExpress.XtraReports.Web.ReportDesigner.Native.ReportDesignerBootstrapper.SessionState = 
        System.Web.SessionState.SessionStateBehavior.Required;
}

Ensure that the handlers for the Report Designer are registered within the application’s web.config file in the httpHandlers and handlers collections.

Note

Since a report document is generated/exported asynchronously, the Current‘s properties are not available during executing the IDataSourceWizardConnectionStringsProvider service’s methods and in the events of the report and its controls.

To overcome these limitations, force synchronous report document creation and/or exporting while the web request is being processed. In your custom WebDocumentViewerOperationLogger implementation, manually call the XtraReport.CreateDocument method in the WebDocumentViewerOperationLogger.BuildStarting method and use the doExportSynchronously delegate in the WebDocumentViewerOperationLogger.ExportDocumentStarting method.

using DevExpress.XtraReports.UI;
using DevExpress.XtraReports.Web.ReportDesigner;
using DevExpress.XtraReports.Web.WebDocumentViewer;

public class CustomLogger : WebDocumentViewerOperationLogger {
   public override Action BuildStarting(string reportId, string reportUrl, XtraReport report, ReportBuildProperties buildProperties) {   
      report.CreateDocument();
      return null;
   }

   public override ExportedDocument ExportDocumentStarting(string documentId, string asyncExportOperationId, string format, ExportOptions options, 
                  PrintingSystemBase printingSystem, Func<ExportedDocument> doExportSynchronously) {
      return doExportSynchronously();
   }
...
}