4

我正在尝试Report使用 ASP.NET Web 应用程序连接到(rdlc 文件)。我正在使用 VS2010 并且Report Server是 2008 版。

我有以下工作正常的报告 URL:

http://server url/Products/_layouts/ReportServer/RSViewerPage.aspx?rv:RelativeReportUrl=/Products/Dashboards/Product_tool.rdl&Source=Server Url/Products/Dashboards/Forms/AllItems.aspx&DefaultItemOpen=1

当我在浏览器中输入该 URL 时,它首先要求输入用户名密码。当我登录然后Report显示就好了。

现在我需要在Report Viewer. 所以我在我的页面上添加了一个Report Viewer控件。aspx我为它配置了 URls,如下所示:

Report Server:** http://server url/Products/_layouts/ReportServer

Report Path:** /Products/Dashboards/Product_tool.rdl

我不确定这是否正确..?

无论如何,在我的PageLoad我有以下代码行:

eportViewer1.ServerReport.ReportServerCredentials = new ReportCredentials("myuser", "mypass");

ReposrtCredentials课程取自:http ://social.msdn.microsoft.com/Forums/en-US/vsreportcontrols/thread/c65abca7-0fdb-40fb-aabe-718f63377a55/ (来自Phil)

现在,当我运行我的 Web 应用程序时,我收到以下错误:

连接到报表服务器的尝试失败。检查您的连接信息以及报表服务器是否为兼容版本。

现在我不确定我提供给的 URLReport Viewer是否正确?或者还有什么问题。

任何人有任何想法..?

4

2 回答 2

4

为了将 SSRS 报告集成到 ASP.NET 应用程序中,请执行以下步骤。

首先,实现 IReportServerConnection2 接口。我做了这样的事情:

  public sealed class CustomReportServerConnection : IReportServerConnection2
    {
        public WindowsIdentity ImpersonationUser
        {
            get
            {
                // Use the default Windows user.  Credentials will be
                // provided by the NetworkCredentials property.
                return null;
            }
        }
        public ICredentials NetworkCredentials
        {
            get
            {
                // Read the user information from the web.config file.  
                // By reading the information on demand instead of 
                // storing it, the credentials will not be stored in 
                // session, reducing the vulnerable surface area to the
                // web.config file, which can be secured with an ACL.

                // User name
                string userName = ConfigurationManager.AppSettings[Utility.Constants.AppConst.REPORT_USER].ToString(); 

                if (string.IsNullOrEmpty(userName))
                    throw new Exception(Utility.Constants.AppConst.MESSAGE_MISSING_USER_NAME);

                // Password
                string password = ConfigurationManager.AppSettings[Utility.Constants.AppConst.REPORT_PASSWORD].ToString();

                if (string.IsNullOrEmpty(password))
                    throw new Exception(Utility.Constants.AppConst.MESSAGE_MISSING_PWD);

                // Domain
                string domain = ConfigurationManager.AppSettings[Utility.Constants.AppConst.REPORTS_DOMAIN].ToString();

                if (string.IsNullOrEmpty(domain))
                    throw new Exception(Utility.Constants.AppConst.MESSAGE_MISSING_DOMAIN);

                return new NetworkCredential(userName, password, domain);
            }
        }
        public bool GetFormsCredentials(out Cookie authCookie, out string userName, out string password, out string authority)
        {
            authCookie = null;
            userName = null;
            password = null;
            authority = null;
            // Not using form credentials
            return false;
        }
        public Uri ReportServerUrl
        {
            get
            {
                string url = ConfigurationManager.AppSettings[Utility.Constants.AppConst.REPORT_SERVER_URL].ToString();

                if (string.IsNullOrEmpty(url))
                    throw new Exception(Utility.Constants.AppConst.MESSAGE_MISSING_URL);

                return new Uri(url);
            }
        }
        public int Timeout
        {
            get
            {
                return int.Parse(ConfigurationManager.AppSettings[Utility.Constants.AppConst.REPORT_SERVER_TIME_OUT].ToString());
                // return 60000; // 60 seconds
            }
        }
        public IEnumerable<Cookie> Cookies
        {
            get
            {
                // No custom cookies
                return null;
            }
        }
        public IEnumerable<string> Headers
        {
            get
            {
                // No custom headers
                return null;
            }
        }
    }

现在在您的 Configuration AppSettings 中放置以下键(或从任何您想要的地方提供这些值):

    <add key="ReportServerUrl" value="http://sqlServerURL/ReportServer_SQL2008R2"/>

    <!--Development TargetReportFolder-->
    <add key="TargetReportFolder" value="/AppReporting/"/>
    <add key="ReportServerTimeOut" value="600000"/>
    <add key="ReportViewerServerConnection" value="FullyQualified Name of ur CustomReportServerConnection,ProjectName"/>
    <add key="ReportsUser" value="ReportUser"/>
    <add key="ReportsPassword" value="reportPassword"/>
    <add key="ReportsDomain" value="myDomain"/>

现在,在您的 .aspx 页面中,拖动一个 reportViewer,如下所示:

<rsweb:ReportViewer ID="RptViewer" runat="server" AsyncRendering="False" SizeToReportContent="true"
            ProcessingMode="Remote" Width="100%" BackColor="#F7F8F9" OnReportError="RptViewer_ReportError"
            OnReportRefresh="RptViewer_ReportRefresh1" Height="">
        </rsweb:ReportViewer>

并在 codeBehind 中配置您的 ReportViewer..ReportParameter正确放置。

它给你一个想法......

关键是,您需要正确进行身份验证,因此编写自定义 ReportServerConnection

于 2013-01-16T13:53:13.477 回答
1

配置报表查看器时,请检查您使用的帐户是否具有查看报表的权限,因为在使用服务器报表时需要您具有访问权限。也看看这个链接。他们会有所帮助:http ://forums.asp.net/t/1562624.aspx/1

于 2013-01-16T12:25:25.303 回答