Répondre

3

`J'ai donc dû changer la façon dont une application ASP.NET 2.0 appelée rapports à partir de pages. À l'origine, j'ai utilisé JavaScript pour ouvrir une nouvelle fenêtre.

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

La question que j'avais été que l'appel window.open ne fonctionne que dans le réseau client et non sur un nouveau serveur Web situé dans leur zone démilitarisée. J'ai dû créer un nouveau rapport WebForm incorporant un contrôle ReportViewer pour afficher les rapports. L'autre problème que j'avais, c'est que le serveur de rapports devait être accessible avec l'authentification Windows car il était utilisé par une autre application pour les rapports et cette application utilisait des rôles pour l'accès aux rapports. Donc, je suis allé obtenir mon contrôle ReportViewer pour usurper l'identité d'un utilisateur Windows. J'ai trouvé la solution à ceci:

Créer 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, je crée un événement pour le bouton pour 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(); 
} 
Questions connexes