我有一个MVC4应用程序,我还有一些报告托管在Azure报告服务上。我知道报表查看器不能直接在MVC Razor页面中工作,我见过带有报表查看器的aspx页面的示例。
然而,我无法让任何示例工作,或者它们是不完整的,或者不支持回发等。
有没有使用Azure报告的完整示例?我正在使用一个iFrame链接到天蓝色的报告,但这是不好的,因为用户需要登录到天蓝色的网站。
谢谢。
发布于 2013-06-10 19:58:06
我以前是这样的,这对我来说很好。您可以下载示例项目来探索:) 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;
}
} https://stackoverflow.com/questions/17023021
复制相似问题