【问题标题】:ASP.NET session has expired or could not be foundASP.NET 会话已过期或找不到
【发布时间】:2012-10-12 11:24:00
【问题描述】:

我在 Windows Azure 上部署了一个 asp.net(VS2010 - .NET 4.0) 应用程序。我正在尝试使用 .NET 报表查看器控件。我正在本地模式下运行报告。 报告工作正常并正确显示。当我尝试将其导出到 Excel/PDF/Word 时,我收到此错误“ASP.NET 会话已过期或找不到”。

这是我的示例代码: ASP.NET

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="RxCloudReports.Default" EnableSessionState="True" %>

<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
</script>
</head>
</head>
<body>
    <form id="form1" runat="server" enctype="multipart/form-data">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>

        <rsweb:ReportViewer ID="ReportViewer1" runat="server" ProcessingMode="Local" SizeToReportContent="true" AsyncRendering = "true" 
                     ShowPageNavigationControls="true"   ShowExportControls="true" ShowToolBar="true" >

        </rsweb:ReportViewer>
</form>
</body>
</html>

C#

DataSet ds = GetDataSet(_ID, _Module);
ReportViewer1.Reset();
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportViewer1.LocalReport.ReportPath = "Reports/Reports1.rdlc";
ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("ReportDS", ds.Tables[0]));
ReportViewer1.LocalReport.Refresh();

【问题讨论】:

    标签: c# asp.net azure reportviewer


    【解决方案1】:

    我已经设置了

    <rsweb:ReportViewer ... KeepSessionAlive="false" />
    

    此后它在 Azure 上运行(至少对我而言)。

    【讨论】:

    • 我试过这个但没有用。我仍然得到同样的错误。异常详细信息:Microsoft.Reporting.WebForms.AspNetSessionExpiredException:ASP.NET 会话已过期或找不到。
    • 任何人对此有任何建议。我感谢您的帮助。谢谢
    【解决方案2】:

    【讨论】:

      【解决方案3】:

      就我而言;生活在 iframe 中的 ReportViewer 控件一切正常,但最近几天我的网站停止工作,原因是谷歌浏览器安全更新;解决方案为我的报表服务器 I.E. 设置了一个子域。我的网站位于https://app.myapp.com 我的报表服务器位于https://reports.myapp.com

      注意:此解决方案仅适用于您使用 iframe 播种报表控件且站点位于不同域中的情况

      参考: Developers: Get Ready for New SameSite=None; Secure Cookie Settings Announcement: SameSite Cookie Handling and .NET Framework 4.7.2 Patch Availability on Azure App Service

      【讨论】:

        【解决方案4】:

        除了网络农场、工作进程循环、会话实际到期等之外,还有另一种情况可能会发生“ASP.NET 会话已过期”错误。

        这种情况非常严重,我没有在 Stackoverflow 上看到针对它发布的答案,所以如果这种情况发生在其他人身上,这有望缩短痛苦。

        这种情况可能发生在任何使用嵌入式报表查看器控件的应用程序中,但如果您的应用程序具有多个经常刷新的嵌入式报表查看器控件,它会更快地表现出来。

        报告查看器控件每次刷新时都会不断创建新的 cookie(不确定原因)。 cookie 名称的后缀为 _SKA。

        由于每个浏览器都对它们将存储的 cookie 数量有限制(对于最新的 IE 版本,它是 50,对于 Chrome 和 Firefox,它是一个更大的数字,但仍然是有限的),cookie 会不断累积,直到达到限制此时浏览器开始丢弃最旧的 cookie,这意味着 ASP.NET 的会话 cookie 最终被丢弃,导致 ASP.NET 会话过期错误。

        所以在这种情况下,它与会话过期或服务器端的任何事情无关。当达到浏览器 cookie 计数限制时,客户端浏览器开始丢弃最旧的 cookie。

        我作为这个问题的解决方案来解决这个问题,其中 cookie 限制问题会导致另一个问题。下面的代码基于该问题中的解决方案: SSRS: Why do SKA-cookies build up until: HTTP 400 Bad Request - Request Too Long

        将此代码添加到 global.asax 将解决该问题:

            void Application_BeginRequest(object sender, EventArgs e) {
                if (Request == null || Request.Cookies == null) {
                    return;
                }
                if (Request.Cookies.Count < 10) {
                    return;
                }
                for (int i = 0; i < Request.Cookies.Count; ++i) {
                    if (StringComparer.OrdinalIgnoreCase.Equals(Request.Cookies[i].Name, System.Web.Security.FormsAuthentication.FormsCookieName)) {
                        continue;
                    }
                    if (!Request.Cookies[i].Name.EndsWith("_SKA", System.StringComparison.OrdinalIgnoreCase)) {
                        continue;
                    }
                    if (i > 10) {
                        break;
                    }
        
                    System.Web.HttpCookie c = new System.Web.HttpCookie(Request.Cookies[i].Name);
                    c.Expires = DateTime.Now.AddDays(-1);
                    c.Path = "/";
                    c.Secure = false;
                    c.HttpOnly = true;
                    Response.Cookies.Set(c);
                }
            }
        

        【讨论】:

          猜你喜欢
          • 2013-12-03
          • 2017-04-14
          • 2012-03-18
          • 2018-03-31
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-06-25
          • 1970-01-01
          相关资源
          最近更新 更多