【问题标题】:ReportViewer is blocking other functionalites until the loading of report viewer is completedReportViewer 正在阻止其他功能,直到报表查看器的加载完成
【发布时间】:2015-07-11 05:10:22
【问题描述】:

这是 ReportViewer 控件:

  <form id="reportForm" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server" AsyncPostBackTimeout="360000">
    </asp:ScriptManager>
    <div>
      <rsweb:ReportViewer ID="mainReportViewer" runat="server" Width="100%" 
            Height="100%" SizeToReportContent="True"  >
      </rsweb:ReportViewer>
    </div>
  </form>

这是页面背后的代码:

protected void Page_Load(object sender, EventArgs e)
{
    if (Session["UserInfo"] == null)
    {
        Response.Redirect("~/account/login", true);
    }
    string ReportPath = "";
    try
    {
        if (mainReportViewer.Page.IsPostBack) return;

        mainReportViewer.ProcessingMode = ProcessingMode.Remote;

        mainReportViewer.ServerReport.ReportServerUrl = new Uri(
            @"" + ConfigurationManager.AppSettings["ReportServer"].ToString()
        );
        ReportPath = Convert.ToString(ConfigurationManager.AppSettings["ReportPath"]);
        if (!string.IsNullOrEmpty(ReportPath))
        {
            if (ReportPath.Substring(0, 1) == "/")
            {
                ReportPath = ReportPath.Substring(1, ReportPath.Length - 1);
            }
            if (ReportPath.Substring(ReportPath.Length - 1, 1) != "/")
            {
                ReportPath = ReportPath + '/';
            }
        }
        else
        {
            ReportPath = "";
        }
        ReportPath = ReportPath + Request["Report"].ToString().Split(".".ToCharArray())[0].ToString();
        mainReportViewer.ServerReport.ReportPath = @"/" + ReportPath;

        ReportParameterCollection parmCol = new ReportParameterCollection();
        string sFrom = "";
        string sTo = "";
        string dateRange = Request["dateRange"].ToString();
        string[] obj = dateRange.Split("-".ToCharArray());
        if (obj.Length > 1)
        {
            sFrom = obj[0].ToString();
            sTo = obj[1].ToString();
        }
        else
            sFrom = obj[0].ToString();
        else if (Request["Report"].ToString().ToUpper() == "SOURCEWISEREPORT_AR.RDL")
        {
            string[] frommonthyear = sFrom.Split(',');
            string[] tomonthyear = sTo.Split(',');

            parmCol.Add(new ReportParameter("FromYear", frommonthyear[1]));
            parmCol.Add(new ReportParameter("FromMonth", frommonthyear[0]));
            parmCol.Add(new ReportParameter("ToYear", tomonthyear[1]));
            parmCol.Add(new ReportParameter("ToMonth", tomonthyear[0]));
            parmCol.Add(new ReportParameter("lang", Convert.ToString(Session["Culture"])));
        }
        mainReportViewer.PromptAreaCollapsed = true;
        mainReportViewer.AsyncRendering = true;
        mainReportViewer.ServerReport.Timeout = System.Threading.Timeout.Infinite;
        mainReportViewer.ServerReport.SetParameters(parmCol);
        mainReportViewer.ShowParameterPrompts = true;
        mainReportViewer.LocalReport.EnableHyperlinks = true;
        mainReportViewer.ServerReport.Refresh();
    }
    catch (Exception ex)
    {
        CommonFunctions.createLog("Reports : " + ex.Message);
    }
}

当我尝试查看报告(它是 asp.net mvc 中的一个视图)时,它会在一个新选项卡中打开以查看报告(这是带有代码文件的 aspx 页面),如果我尝试从在新选项卡中的报告完全加载之前,不会加载上一个选项卡。我尝试了一切,但还没有找到解决方案。需要帮助

【问题讨论】:

  • 这是否被错误标记为 mvc 问题? Runat:server 和后面的代码不是 mvc 框架的一部分
  • 如上所述,aspx 页面已添加到我的 mvc 项目中。查看报告的链接位于 mvc 视图页面中,报告本身以 aspx 页面打开,以使用报告查看器控件。简而言之,我的 mvc 应用程序中集成了一个 aspx/aspx.cs 页面来查看报告

标签: asp.net .net asp.net-mvc reportviewer


【解决方案1】:

意思是,如果我尝试从上一个选项卡打开任何链接,则在新选项卡中的报告完全加载之前页面不会被加载

您需要分析您的应用程序。很可能您的请求已排队尝试获取用户会话状态的写锁定。

你可以阅读更多关于这个问题here

为了防止两个页面同时修改进程中的 Session 变量,ASP.NET 运行时使用了锁。当对读取和写入 Session 变量的页面的请求到达时,运行时会获取写入器锁。 写入器锁将阻止同一会话中可能写入相同会话变量的其他页面。

强调我的。

为了缓解这种情况,you can enable or disable session state for individual pages, or declare your usage of session state as "read only"

注意不要意外选择错误的会话状态类型(启用、禁用、只读)。需要正确设置才能让您的应用程序正常工作。

【讨论】:

  • 禁用或只读不适用于报表查看器。它没有得到数据和错误
  • 你不能因为你使用它而禁用它:if (Session["UserInfo"] == null) 就像我说的,不要选错类型。
  • 那如何进一步发展?报告需要时间来加载,这意味着在报告完成之前其他链接被阻止加载。我的应用程序是在 asp.net MVC 中开发的,但报告部分是使用 aspx/aspx.cs 页面创建的。我进行了故障排除并找到了一些要点。您认为报告查看器自动生成的这个 javascipt 可能导致了这个问题吗?有很多这样的javascript:
  • 分析你的意思是改变应用程序?我有点卡住了,不知道如何继续。
  • 这些应用程序将显示您的网站在哪里花费时间,这将确认您是否遇到会话状态问题red-gate.com/products/dotnet-development/…jetbrains.com/profiler 简要教程:red-gate.com/products/dotnet-development/…
【解决方案2】:

由于 ReportViewer 用户的会话状态不断,它使用了一个阻止页面加载的锁。我解决问题的方法是:

  • 创建Class 并实现IReportServerConnection2 interface
  • add key="ReportViewerServerConnection" value="MyNamespace.MyClass, MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken= 00000000000000000 "/&gt;web.config 文件在 &lt;appsettings&gt;
  • ReportViewer.aspx页面设置EnableSessionState = "Readonly"

这个帖子帮助我解决了我的问题: The attempt to connect to the report server failed - Setting URL and Path in ASP.NET?

【讨论】:

    【解决方案3】:

    你可以试试吗?

    System.Threading.Thread thLoadReport = new System.Threading.Thread(new System.Threading.ThreadStart(LoadReport));
    thLoadReport.Start();
    
    private void LoadReport()
    {
        // Invoke necessary controls here for eg.
        mainReportViewer.Invoke((MethodInvoker)delegate {
            // your report loading here
        });
    }
    

    如果您需要更多帮助,请告诉我。

    【讨论】:

    • 没有调用方法 w.r.t mainReportViewer
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-11
    • 2016-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多