Search code examples
asp.net-mvc-4razorreporting-servicesreportviewer

MVC4 & Azure Reporting Reports


I have an MVC 4 application and i also have some reports the are hosted on Azure Reporting services. I know that the report viewer will not work directly in an MVC Razor page and have seen examples of an aspx page with the report viewer on that.

however i have not been able to get any of the examples to work or they are incomplete or do not support postbacks etc..

are there any complete examples that will work with Azure Reports? I am using an iFrame at the moment to link to the azure reports but this is not good as the user needs to login to the azure site.

thank you.


Solution

  • i used like this, which works fine for me. you can download the sample project to explore :) 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;
        }
    }