回答

3

`所以我不得不改变ASP.NET 2.0应用程序从页面调用报表的方式。最初,我使用JavaScript打开一个新窗口。

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

我的问题是,window.open调用将只在客户端网络中,而不是位于其DMZ一个新的Web服务器上运行。我不得不创建一个嵌入了ReportViewer控件来查看报表的新报表WebForm。

我遇到的另一个问题是报表服务器必须使用Windows身份验证进行访问,因为报表服务器正在被其他应用程序用于报告,并且该应用使用角色进行报表访问。因此,我去让我的ReportViewer控件模仿一个Windows用户。我发现解决方案是这样的:

创建一个新类,该类实现用于访问报告的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(); 
}