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 サーバーでは機能しないことでした。レポートを表示するには、ReportViewer コントロールを埋め込んだ新しいレポート Web フォームを作成する必要がありました。
私が抱えていたもう 1 つの問題は、レポート サーバーが別のアプリケーションによってレポートに使用されており、そのアプリがレポート アクセスにロールを使用していたため、Windows 認証を使用してレポート サーバーにアクセスする必要があるということでした。そこで、Windows ユーザーになりすますための ReportViewer コントロールを取得することにしました。解決策は次のとおりであることがわかりました。
レポートにアクセスするための 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