1

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

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

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

谢谢你。

4

1 回答 1

2

我这样用过,对我来说很好用。您可以下载示例项目进行探索 :) 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;
    }
}  
于 2013-06-10T11:58:06.033 回答