How to handle report browsing session session exception

I have the following situation:

Microsoft Report Viewer 2010 is used to display reports (.rdlc files) locally in an ASP.NET web application. Report data is provided by assigning a data source in code behind the ASPX page. Here is an example:

if(!IsPostBack){
ReportViewer1.Reset();
ReportDataSource reportDataSource = new ReportDataSource();

reportDataSource.Name = "DataContainerType";
reportDataSource.Value = DatasourceOnPage;
reportDataSource.DataSourceId = "DatasourceOnPageID";
reportDataSource.DataMember = "DataSourceView";

ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.DisplayName = "ReportName";
ReportViewer1.LocalReport.ReportEmbeddedResource = "Reportfile.rdlc";
ReportViewer1.LocalReport.DataSources.Add(reportDataSource);
}

This usually works fine, each report has very good workloads.

When I leave the page open until the workflow processes, try updating the report or doing some postback on the report page, I get an (unhandled) ASP.NET expired exception.

:     : AspNetSessionExpiredException     : Die ASP.NET-Sitzung ist abgelaufen oder konnte nicht gefunden > werden.    Microsoft.Reporting.WebForms.ViewerDataOperation..ctor()    Microsoft.Reporting.WebForms.HttpHandler.GetHandler(String operationType)    Microsoft.Reporting.WebForms.HttpHandler.ProcessRequest( HttpContext)   at > System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionS > tep.Execute()    System.Web.HttpApplication.ExecuteStep( IExecutionStep, Boolean & > )

IIS 5 . InProc web.config, , , . ASP.NET, . , .

, . , , , Report Viewer , .

, - ReportViewer, . - , IsPostBack, .

, , , . , .

Windows Server 2003 .NET 4.0 Report Viewer 2010

, , ?

+3
2

, , . , , , .

script, , . , .

public class ReportPage: System.Web.UI.Page
{

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        #region check for lost session
        if (Context.Session != null)
        {
            if (Session.IsNewSession)
            {
                string cookieHeader = Request.Headers["Cookie"];
                if ((null != cookieHeader) && (cookieHeader.IndexOf("ASP.NET_SessionId") >= 0))
                {
                    Response.Redirect(Request.Url.ToString());
                }
            }
        }

        #endregion check for lost session

        #region generate keepsessionalive script 


        StringBuilder sb = new StringBuilder();
        sb.Append("$(function () {setInterval(KeepSessionAlive, " + GetSessionTimeoutInMs() + ");");
        sb.Append("});");
        sb.Append("function KeepSessionAlive() {");
        sb.Append(string.Format("$.post('{0}', null);", ResolveUrl("~/KeepSessionAlive.ashx")));
        sb.Append("};");

        // register on page
         Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "SessionKeepAlive", sb.ToString(), true);

        #endregion generate keepsessionalive script
    }

    private int GetSessionTimeoutInMs()
    {
        return (this.Session.Timeout * 60000) - 10000;           
    }
}

"keep-alive" script http ( .ashx), , ( , , ). :

 public class KeepSessionAlive : IHttpHandler, IRequiresSessionState
{

    public void ProcessRequest(HttpContext context)
    {
        context.Session["KeepSessionAlive"] = "KeepAlive!";
    }

    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}
+1

1?

, A) setting a specfic time of day for recycle ( ) B) limit worker processes to max of 1 in app pool settings.

0

Source: https://habr.com/ru/post/1757116/


All Articles