Comment visualiser les rapports SQL Server 2005 Reporting Services à partir du contrôle ReportViewer dans DMZ

StackOverflow https://stackoverflow.com/questions/63882

Question

Je souhaite pouvoir afficher un rapport SQL Server 2005 Reporting Services à partir d'une application ASP.NET dans une zone démilitarisée via un contrôle ReportViewer. Les serveurs SQL et SSRS sont derrière le pare-feu.

Était-ce utile?

La solution

`J'ai donc dû changer la manière dont une application ASP.NET 2.0 appelait les rapports depuis les pages. À l’origine, j’utilisais JavaScript pour ouvrir une nouvelle fenêtre.

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

Le problème que j’avais était que l’appel window.open ne fonctionnerait que sur le réseau client et non sur un nouveau serveur Web situé dans leur zone démilitarisée. Je devais créer un nouveau rapport WebForm incorporant un contrôle ReportViewer pour afficher les rapports.

Mon autre problème était que l'accès à Report Server devait s'effectuer avec l'authentification Windows, car il était utilisé par une autre application pour les rapports et que cette application utilisait des rôles pour l'accès aux rapports. Alors je suis allé chercher mon contrôle ReportViewer pour emprunter l'identité d'un utilisateur Windows. J'ai trouvé la solution:

Créez une nouvelle classe qui implémente l'interface Microsoft.Reporting.WebForms.IReportServerCredentials pour accéder aux rapports.

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

Ensuite, j'ai créé un événement pour le bouton permettant d'appeler le rapport:

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();
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top