Skip to main content
A newer version of this page is available. .

Accessing an HttpContext in Services of HTML5 Reporting Controls

  • 3 minutes to read

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

Tip

Refer to the documents below for complete lists of available services:

To enable these services to access values stored in HttpContext.Session, do one of the following, depending on your application’s target platform:

  • In ASP.NET WebForms application, click the control’s smart tag and select Required in the drop-down list for the Session State property.

    report-designer-smart-tag-session-state

  • In an ASP.NET MVC project, you can specify this 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 required controls are registered within the application’s web.config file in the httpHandlers and handlers collections.

For an online example, refer to How to access the values stored in HttpContext/Session while working with the ASP.NET HTML5 Document Viewer and End-User Report Designer controls.

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();
   }
...
}
See Also