回答

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(); 
} 
相關問題