【问题标题】:MVC4 & Azure Reporting ReportsMVC4 和 Azure 报告报告
【发布时间】:2013-06-10 11:39:17
【问题描述】:

我有一个 MVC 4 应用程序,还有一些托管在 Azure 报告服务上的报告。 我知道报表查看器不能直接在 MVC Razor 页面中工作,并且已经看到了带有报表查看器的 aspx 页面的示例。

但是我无法让任何示例正常工作,或者它们不完整或不支持回发等。

是否有适用于 Azure Reports 的完整示例? 我目前正在使用 iFrame 链接到 azure 报告,但这并不好,因为用户需要登录到 azure 站点。

谢谢。

【问题讨论】:

    标签: asp.net-mvc-4 razor reporting-services reportviewer


    【解决方案1】:

    我就是这样用的,对我来说很好用。您可以下载示例项目进行探索:) Sample Project for Azure + SSRS + MVC4

    DataSourceCredentials cred = new DataSourceCredentials();
    cred.Name = "DataSource1";
    cred.UserId = "YourSQLServerLogin"; // this is the UserID which you used to Connect SQL
    cred.Password = "YourSQLServerPassword";
    ReportViewer1.ShowParameterPrompts = false;
    ReportViewer1.ShowCredentialPrompts = false;
    if(!this.IsPostBack) // make Sure you add this, or else Reporting will go in infinite loop. 
    {
      try
      {
          ReportViewer1.ServerReport.ReportServerUrl = 
            new Uri(ConfigurationManager.AppSettings["SERVER_NAME"]);
          ReportViewer1.ServerReport.ReportPath = 
            ConfigurationManager.AppSettings["REPORT_PATH"];
    
          ReportViewer1.ServerReport.ReportServerCredentials = new ReportCredential();
          ReportViewer1.ServerReport.SetDataSourceCredentials(new DataSourceCredentials[] { cred });
      }
      catch (Exception ex)
      {
          throw;
      }
    } 
    
    
    public class ReportCredential : IReportServerCredentials
    {
        public WindowsIdentity ImpersonationUser
        {
            get
            {
                return null;
            }
        }
        public ICredentials NetworkCredentials
        {
            get
            {
                return null;
            }
        }
        public bool GetFormsCredentials(out Cookie authCookie, 
                    out string user, out string password, out string authority)
        {
            authCookie = null;
            user = ConfigurationManager.AppSettings["USERNAME"];
            password = ConfigurationManager.AppSettings["PASSWORD"];
            authority = ConfigurationManager.AppSettings["SERVER_NAME"];
            return true;
        }
    }  
    

    【讨论】:

    • 非常感谢,这是一个很好的答案,我现在已经开始运行了。您是否为每个报告创建一个单独的 .aspx 页面并将它们加载到 iFrame 中?此外,在代码隐藏类中拥有数据库 DataSourceCredentials 信息的安全性如何?谢谢
    猜你喜欢
    • 1970-01-01
    • 2018-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多