ReportViewer控件不显示报告

时间:2013-07-10 15:53:38

标签: c# asp.net-mvc reporting-services web-config reportviewer2008

我几乎到处寻找解决这个问题的方法,但还没找到一个对我有用的方法。我在托管服务器上设置了报告服务器(2008 R2)。我使用报表生成器从头创建了一个报表,在使用其URL登录到报表服务器时对其进行了测试,并成功生成了报表。

当我尝试从MVC应用程序查看报告时,只有报告工具栏呈现(显示导出,打印,页面和视图报告按钮)。它显示它是“正在加载”,并且在它完成之后它只是一个空白报告,但是它在工具栏上显示了正确的参数,如果我在代码中更改了参数的名称,则返回一个错误,指出参数没有存在;所以我知道地址user / pw信息是否正确。

页面的代码和标记

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<%@ Import Namespace="Comp.Proj.Core.Model"%>
<%@ Import Namespace="Comp.Proj.Core.Service" %>
<%@ Import Namespace="Microsoft.Reporting.WebForms" %>
<%@ Import Namespace="System.Security.Principal" %>
<%@ Import Namespace="System.Net" %>
<%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
    Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

  <h2><a href="/Reporting">Back to Reports</a> / <%=ViewData["Report"]%></h2>
    <form action="/Reporting/DateViewer" method="get">
      Start Date:
      <input type="text" name="start" class="datepicker" value="<%=ViewData[" Start "] %>" /> End Date:
      <input type="text" name="end" class="datepicker" value="<%=ViewData[" End "] %>" />
      <input type="hidden" name="id" value="<%=ViewData[" Report "] %>" />
      <input type="submit" class="button" value="Run" />
    </form>

    <script runat="server" language="C#">
      protected void Page_Load(object sender, EventArgs e) {
        try {
          if (!IsPostBack) {
            if (ViewData["Start"] != null) {
              var param = new List < ReportParameter > ();


              var start = new ReportParameter("start", ViewData["Start"].ToString());
              var end = new ReportParameter("end", ViewData["End"].ToString());
              var region = new ReportParameter("region", "2");
              param.Add(start);
              param.Add(end);
              param.Add(region);
              ReportViewer1.Width = 1100;
              ReportViewer1.Height = 900;
              ReportViewer1.ShowCredentialPrompts = false;
              ReportViewer1.ShowDocumentMapButton = false;
              ReportViewer1.ShowExportControls = true;
              ReportViewer1.ShowFindControls = false;
              ReportViewer1.ShowPrintButton = true;
              ReportViewer1.ShowPromptAreaButton = false;
              ReportViewer1.ShowRefreshButton = false;
              ReportViewer1.ShowToolBar = true;
              ReportViewer1.ShowZoomControl = false;
              ReportViewer1.SizeToReportContent = true;
              ReportViewer1.ProcessingMode = ProcessingMode.Remote;
              IReportServerCredentials irsc =
                new CustomReportCredentials(ConfigurationManager.AppSettings["ReportServerUser"],
                                            ConfigurationManager.AppSettings["ReportServerPassword"], "SERVERNAME");
              ReportViewer1.ServerReport.ReportServerCredentials = irsc;
              ReportViewer1.ServerReport.ReportServerUrl =
                new Uri(string.Format("http://{0}/ReportServer",
                                      ConfigurationManager.AppSettings["ReportServerUrl"]));
              ReportViewer1.ServerReport.ReportPath = string.Format("/{0}", ViewData["Report"]);
              ReportViewer1.ServerReport.SetParameters(param);
              ReportViewer1.ShowReportBody = true;
              ReportViewer1.ServerReport.Refresh();
            }
          }
        } catch (Exception ex) {
          Response.Write(ex.Message);
        }
      }
    </script>

    <form id="form1" runat="server">
      <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
      <div>
        <rsweb:ReportViewer ID="ReportViewer1" runat="server" />
      </div>
    </form>

</asp:Content>

网络配置

<assemblies>
    <add assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
    <add assembly="Microsoft.ReportViewer.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
</assemblies>

<buildProviders>
    <add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</buildProviders>

<system.webServer>
    <handlers>
        <add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
    </handlers>
</system.webServer>

5 个答案:

答案 0 :(得分:6)

我终于开始工作了。对于那些和我有同样问题的人来说,这就是我为了让它发挥作用所做的。

在页面指令中,设置EnableEventValidation="false"和报告控件集AsyncRendering="false"

答案 1 :(得分:1)

我从不添加这些解决方案,但我觉得该是我“回馈”而不是仅仅“带走”的时候了。

当我的页面在页面上具有以下内容时,报表查看器将显示参数,但不显示实际报表。请注意,我有AysncRendering = false。 因此,此代码无法正常工作(VB)。

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim UserName = HttpContext.Current.User.Identity.Name
    Dim paramList As New Generic.List(Of ReportParameter)
    paramList.Add(New ReportParameter("UserID", UserName, False))
    ReportViewer1.ServerReport.SetParameters(paramList)
End Sub

但是当我添加以下几行,而没有进行其他更改时,整个报告就会加载。

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim UserName = HttpContext.Current.User.Identity.Name
    If IsPostBack = False Then
        ReportViewer1.Width = 900
        ReportViewer1.Height = 900

        Dim paramList As New Generic.List(Of ReportParameter)
        paramList.Add(New ReportParameter("UserID", UserName, False))
        ReportViewer1.ServerReport.SetParameters(paramList)
        ReportViewer1.ShowReportBody = True
        ReportViewer1.ServerReport.Refresh()
    End If

请注意,我没有进行任何页面声明更改,就像之前提到的此处的帖子一样。

答案 2 :(得分:0)

我所做的是确保所有web.config页面都使用引用ReportViewer 10。 奇怪的是,屏幕仍显示空白页面。单击“刷新”,它出现了。这可能是由于会议。

答案 3 :(得分:0)

下面的代码对我有用

我正在使用报告服务 14 并在后面的代码中设置 ReportViewer1.ServerReport.ReportServerUrl 和 ReportViewer1.ServerReport.ReportPath。

Report1.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Report1.aspx.cs" Inherits="CIEM.Web.Reports.Report1" %>
<%@ Register assembly="Microsoft.ReportViewer.WebForms, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" namespace="Microsoft.Reporting.WebForms" tagprefix="rsweb" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> 
<title></title>
    <style>
    html,body,form,#div1 {
        height: 100%; 
    }
</style>
</head>
<body>
<form id="form1" runat="server">
<div id="div1" >
        <asp:ScriptManager runat="server"></asp:ScriptManager>
    <rsweb:ReportViewer ID="ReportViewer1" runat="server" ProcessingMode="Remote" Height="100%" Width="100%">
    </rsweb:ReportViewer>
</div>
</form>
</body>

https://docs.microsoft.com/en-us/sql/reporting-services/application-integration/integrating-reporting-services-using-reportviewer-controls-get-started?view=sql-server-2017#set-the-height-of-all-the-ancestors-to-100

答案 4 :(得分:-1)

https://msdn.microsoft.com/en-us/library/ms252090.aspx

  

1.明确地将ReportViewer控件上的高度设置为实际值而不是百分比   2.将以下样式设置添加到标记:html,body,form {height:100%}。通过强制HTML,   身体,并形成标签到最大高度,框架中使用的框架   ReportViewer控件也将增长到最大高度   在页面上可见。
  3.从页面中删除xhtml文档类型。 (重要)