Skip to main content

Access HttpContext.Session in Services

  • 2 minutes to read

The Web Document Viewer processes requests coming from its services using separate HTTP handler modules, which do not provide access to HttpContext.Session.

Tip

Refer to the Register Services in the Document Viewer document for the complete list of available services.

To enable these services to access values stored in HttpContext.Session, click the control’s smart tag and select Required in the drop-down list for the Session State property.

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;
}

Ensure that the handler for the Document Viewer is 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();
   }
...
}