【问题标题】:Cannot list out reports from Reporting Services through asp.net page by using DefaultCredentials无法使用 DefaultCredentials 通过 asp.net 页面列出来自 Reporting Services 的报告
【发布时间】:2026-01-08 20:15:01
【问题描述】:

--------- 背景------------------
我目前正在尝试在我们的内部网中为我们的员工构建一个 Web 界面。 我想根据this 的谎言构建一些东西,如果他们能够 访问他们有权访问的报告,以及我们可以访问的一些应用程序 正在努力构建基于部门管理不同流程的建筑。

我们有一个应用服务器和一个报告服务服务器 (SQL 2008)。

---------到目前为止我所做的--------

我添加了对http://prodrpt/ReportServer/reportservice2005.asmx 的网络引用 我既可以看到服务列表,也可以通过 Internet Explorer 访问它们(当我直接导航到它们时)

Web Config 使用 认证方式:Windows 身份模拟 = true

--------------问题-------------------------------- --

当我尝试像这样传递用户凭据时出现问题

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim res As String = "---"

    Dim rs As New ReportingService2005()

    rs.Credentials = System.Net.CredentialCache.DefaultCredentials
    Dim items As New prodrpt.CatalogItem()

    For Each item In rs.ListChildren("/", True)
        res = res + item.Name + " | " + item.Path + " | " + item.Type.ToString + "<br />"
    Next
    Response.Write(res)

    cont.InnerHtml = res
End Sub

返回此错误

请求失败,HTTP 状态为 401:未授权。

Line 925:        [return: System.Xml.Serialization.XmlArrayAttribute("CatalogItems")]
Line 926:        public CatalogItem[] ListChildren(string Item, bool Recursive) {
Line 927:            object[] results = this.Invoke("ListChildren", new object[] {
Line 928:                        Item,
Line 929:                        Recursive});


[WebException: The request failed with HTTP status 401: Unauthorized.]
   System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) +412782
   System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) +300
   prodrpt.ReportingService2005.ListChildren(String Item, Boolean Recursive) in c:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\root\e22c2559\92c7e946\App_WebReferences.nrvcuhh0.1.cs:927
   apps_Payroll_Main.Page_Load(Object sender, EventArgs e) in C:\inetpub\wwwroot\apps\Payroll\Main.aspx.vb:16
   System.Web.UI.Control.OnLoad(EventArgs e) +132
   System.Web.UI.Control.LoadRecursive() +66
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428

如果我替换 rs.Credentials = System.Net.CredentialCache.DefaultCredentials

rs.Credentials = New System.Net.NetworkCredential("username", "password")

通过直接传递我的凭据它可以工作,但我希望它自动挑选出凭据。

我还注意到,如果我输入“域\用户名”之类的凭据会失败,但如果我只输入“用户名”而不输入域,它会起作用。

我现在不知道该尝试什么,任何帮助将不胜感激。

谢谢。

【问题讨论】:

    标签: asp.net sql-server reporting-services


    【解决方案1】:

    如果您在 IIS 上运行您的网站,您是否会收到未经授权的消息?在内置开发服务器上运行应用程序时是否有效?如果您仅在 IIS 上收到错误,我想您必须将应用程序池标识设置为有权访问 Web 服务的域用户。

    【讨论】:

    • 当我从应用程序服务器运行该应用程序时(IIS 打开 IE 浏览页面),该应用程序似乎可以工作,但当我从任何其他机器运行它时却不行。
    • 我跳回这个项目,注意到它似乎只在我通过 localhost 运行时才获取凭据。我发现这个链接link 似乎指出了一个可能的原因和解决方案,但目前它有点超出我的想象,所以我需要阅读一些内容来测试它。
    最近更新 更多