Asp.net

ReportViewer 正在阻止其他功能,直到報表查看器的載入完成

  • May 12, 2015

這是 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 頁面),並且意味著如果我嘗試打開前一個選項卡中的任何連結在新選項卡中的報告完全載入之前,頁面不會載入。我嘗試了一切,但還沒有找到解決方案。需要幫忙

意思是,如果我嘗試從上一個選項卡打開任何連結,則在新選項卡中的報告完全載入之前,該頁面不會被載入

您需要分析您的應用程序。您的請求很可能已排隊嘗試獲取使用者會話狀態的寫鎖定。

您可以在此處閱讀有關該問題的更多資訊:

為了防止兩個頁面同時修改程序中的 Session 變數,ASP.NET 執行時使用了鎖。當對讀取和寫入 Session 變數的頁面的請求到達時,執行時會獲取寫入器鎖。寫入器鎖將阻止同一會話中可能寫入相同會話變數的其他頁面。

強調我的。

為了緩解這種情況,您可以啟用或禁用單個頁面的會話狀態,或者將會話狀態的使用聲明為“只讀”

但是請注意不要意外選擇錯誤的會話狀態類型(啟用、禁用、只讀)。需要正確設置它才能使您的應用程序正常工作。

引用自:https://stackoverflow.com/questions/29985689