How do you view SQL Server 2005 Reporting Services reports from ReportViewer Control in DMZ

元气小坏坏 提交于 2020-01-14 05:39:10

问题


I want to be able to view a SQL Server 2005 Reporting Services report from an ASP.NET application in a DMZ through a ReportViewer control. The SQLand SSRS server are behind the firewall.


回答1:


`So I had to change the way an ASP.NET 2.0 application called reports from pages. Originally, I used JavaScript to open a new window.

ViewCostReport.OnClientClick = "window.open('" + Report.GetProjectCostURL(_PromotionID) + "','ProjectCost','resizable=yes')";

The issue I had was that the window.open call would only work within the client network and not on a new web server located in their DMZ. I had to create a new report WebForm that embedded a ReportViewer control to view the reports.

The other issue I had is that the Report Server had to be accessed with windows Authentication since it was being used by another application for reports and that app used roles for report access. So off I went to get my ReportViewer control to impersonate a windows user. I found the solution to be this:

Create a new class which implements the Microsoft.Reporting.WebForms.IReportServerCredentials interface for accessing the reports.

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;
    }
}

Then I created an event for the button to call the report:

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();
}


来源:https://stackoverflow.com/questions/63882/how-do-you-view-sql-server-2005-reporting-services-reports-from-reportviewer-con

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!