xtrareports-118910-web-reporting-asp-net-webforms-reporting-document-viewer-in-asp-net-webforms-reporting-customization-access-httpcontext-session-in-services.md
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;
}
Private Sub Application_Start(sender As Object, e As EventArgs)
DevExpress.XtraReports.Web.WebDocumentViewer.Native.WebDocumentViewerBootstrapper.SessionState =
System.Web.SessionState.SessionStateBehavior.Required
End Sub
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();
}
...
}
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraReports.Web.ReportDesigner
Imports DevExpress.XtraReports.Web.WebDocumentViewer
Public Class CustomLogger
Inherits WebDocumentViewerOperationLogger
Public Overrides Function BuildStarting(reportId As String, reportUrl As String, report As XtraReport, buildProperties As ReportBuildProperties) As Action
report.CreateDocument()
Return Nothing
End Function
Public Overrides Function ExportDocumentStarting(documentId As String, asyncExportOperationId As String, format As String, options As ExportOptions,
printingSystem As PrintingSystemBase, doExportSynchronously As Func(Of ExportedDocument)) As ExportedDocument
Return doExportSynchronously()
End Function
...
End Class