2010-09-09 199 views
2

我有一個asp.net c#web應用程序,包含遠程處理模式報告。我正在使用報表查看器控件來呈現報表。當我以調試模式運行應用程序時,我能夠查看我的報告,但是當我將應用程序發佈到其他服務器時,我收到以下錯誤消息:報告查看器錯誤:請求失敗,HTTP狀態401:未授權

HTTP狀態401的請求失敗:未經授權。

我的報表服務器位於與我發佈的Web應用程序的位置不同的服務器上。我已經添加了新的角色分配到我的報告服務器,並添加到我的web.config但錯誤仍然存​​在。我想我在reportviewer的aspx頁面中缺少一些東西。

任何輸入,將不勝感激。

回答

2

我假設你已經設置你的代碼隱藏的服務器,如本

reportviewer.ServerReport.ReportServerUrl = "http://{server_ip}/reportserver"; 

或通過報表查看器控件的屬性。確保將{server_ip}更改爲報表服務器的實際值。

我以前見過的其他類似問題與訪問個人報告有關。由於這是跨服務器,因此您需要設置代理用戶才能查看報告。

這裏有兩個例子來自MSDN:

Example 1

Example 2

+0

我已經設置爲你所提到的報表服務器URL中使用Page_Load & Page_Init。我嘗試的另一個測試是從我的應用程序發佈的服務器轉到我的報告服務器的URL。它提示我輸入用戶名/密碼,當我使用domain_name /用戶名和密碼時,我可以查看報告服務器。我查看了你的鏈接並試圖添加下面的代碼:ReportViewer1.ServerReport.ReportServerCredentials = new ReportServerCredentials(「username」,「pwd」,「domain」);我已經導入了Microsoft.Reporting.Webforms,但它說無法找到類型或名稱空間。 – user438331 2010-09-09 18:59:00

+0

首先,只需確保將{server_ip}替換爲reportserver的實際IP。其次,您實際上需要從提供的鏈接中包含該類,以便它可以用作服務器憑據。試試看看它是否能解決你的問題。祝你好運! – Madison 2010-09-09 22:05:52

+0

感謝您的回覆。我已經使用reportserver url報告server_ip。我將你的Example2中的代碼添加到我的代碼中。 但是,現在當我測試我的應用程序並嘗試在本地運行報告時,它不會返回任何內容。沒有錯誤,但也沒有報告。即使我已經在我的web.config文件和我的reportviewer.aspx文件中指定了它,我認爲它不再訪問reportserver網址。 此前,這些報告在本地運行良好。 – user438331 2010-09-13 18:14:32

0

是的!以這種方式

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 

    ReportViewer1.Visible = True 
    Dim strReportsFolder As String = ConfigurationManager.AppSettings("ReportsFolder") 
    Dim reportName As String = "report1" 
    ReportViewer1.ServerReport.ReportPath = strReportsFolder + reportName 

End Sub 

Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As EventArgs) 

    PopulateReport(ReportViewer1, "") 

End Sub 

Public Shared Sub PopulateReport(ByVal rptViewer As ReportViewer, ByVal reportName As String) 

    Dim strReportServer As String = ConfigurationManager.AppSettings("ReportServer") 
    Dim strUserName As String = ConfigurationManager.AppSettings("Username") 
    Dim strPassword As String = ConfigurationManager.AppSettings("Password") 
    Dim strDomain As String = ConfigurationManager.AppSettings("Domain") 

    rptViewer.ServerReport.ReportServerUrl = New Uri(strReportServer) 
    rptViewer.ServerReport.ReportServerCredentials = New ReportViewerCredentials(strUserName, strPassword) 

End Sub 
+0

雖然你沒有對域做任何事情? – Yodacheese 2013-11-21 06:23:01

相關問題