如何从 DMZ 中的 ReportViewer 控件查看 SQL Server 2005 Reporting Services 报告
-
09-06-2019 - |
题
我希望能够通过 ReportViewer 控件从 DMZ 中的 ASP.NET 应用程序查看 SQL Server 2005 Reporting Services 报告。SQL 和 SSRS 服务器位于防火墙后面。
解决方案
`因此,我必须更改 ASP.NET 2.0 应用程序从页面调用报告的方式。最初,我使用 JavaScript 打开一个新窗口。
ViewCostReport.OnClientClick = "window.open('" + Report.GetProjectCostURL(_PromotionID) + "','ProjectCost','resizable=yes')";
我遇到的问题是 window.open 调用只能在客户端网络内工作,而不能在位于 DMZ 中的新 Web 服务器上工作。我必须创建一个新的报告 WebForm,其中嵌入了 ReportViewer 控件来查看报告。
我遇到的另一个问题是,必须使用 Windows 身份验证来访问报表服务器,因为另一个应用程序正在使用它来生成报表,并且该应用程序使用角色来进行报表访问。因此,我开始使用 ReportViewer 控件来模拟 Windows 用户。我发现解决方案是这样的:
创建一个新类,该类实现 Microsoft.Reporting.WebForms.IReportServerCredentials 接口以访问报表。
public class ReportCredentials : Microsoft.Reporting.WebForms.IReportServerCredentials
{
string _userName, _password, _domain;
public ReportCredentials(string userName, string password, string domain)
{
_userName = userName;
_password = password;
_domain = domain;
}
public System.Security.Principal.WindowsIdentity ImpersonationUser
{
get
{
return null;
}
}
public System.Net.ICredentials NetworkCredentials
{
get
{
return new System.Net.NetworkCredential(_userName, _password, _domain);
}
}
public bool GetFormsCredentials(out System.Net.Cookie authCoki, out string userName, out string password, out string authority)
{
userName = _userName;
password = _password;
authority = _domain;
authCoki = new System.Net.Cookie(".ASPXAUTH", ".ASPXAUTH", "/", "Domain");
return true;
}
}
然后我为按钮创建了一个事件来调用报告:
protected void btnReport_Click(object sender, EventArgs e)
{
ReportParameter[] parm = new ReportParameter[1];
parm[0] =new ReportParameter("PromotionID",_PromotionID);
ReportViewer.ShowCredentialPrompts = false;
ReportViewer.ServerReport.ReportServerCredentials = new ReportCredentials("Username", "Password", "Domain");
ReportViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
ReportViewer.ServerReport.ReportServerUrl = new System.Uri("http://ReportServer/ReportServer");
ReportViewer.ServerReport.ReportPath = "/ReportFolder/ReportName";
ReportViewer.ServerReport.SetParameters(parm);
ReportViewer.ServerReport.Refresh();
}
不隶属于 StackOverflow