Как вы просматриваете отчеты служб SQL Server 2005 Reporting Services из элемента управления ReportViewer в DMZ
-
09-06-2019 - |
Вопрос
Я хочу иметь возможность просматривать отчет служб SQL Server 2005 Reporting Services из ASP.NET приложения в DMZ через элемент управления ReportViewer.Сервер SSRS SQLand находится за брандмауэром.
Решение
Поэтому мне пришлось изменить способ, которым приложение ASP.NET 2.0 вызывало отчеты со страниц.Первоначально я использовал JavaScript для открытия нового окна.
ViewCostReport.OnClientClick = "window.open('" + Report.GetProjectCostURL(_PromotionID) + "','ProjectCost','resizable=yes')";
Проблема, с которой я столкнулся, заключалась в том, что вызов window.open будет работать только в клиентской сети, а не на новом веб-сервере, расположенном в их DMZ.Мне пришлось создать новую веб-форму отчета, в которую был встроен элемент управления ReportViewer для просмотра отчетов.
Другая проблема, с которой я столкнулся, заключается в том, что доступ к серверу отчетов должен был осуществляться с помощью проверки подлинности Windows, поскольку он использовался другим приложением для отчетов, и это приложение использовало роли для доступа к отчетам.Итак, я пошел, чтобы заставить свой элемент управления ReportViewer выдавать себя за пользователя Windows.Я нашел решение следующим образом:
Создайте новый класс, который реализует Microsoft.Reporting.Веб-формы.Интерфейс 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();
}