【问题标题】:Passing server credentials to SSRS将服务器凭据传递给 SSRS
【发布时间】:2015-03-18 15:04:02
【问题描述】:

我在我的一个 asp 项目中有一个函数,它访问服务器以获取报告并返回它的字节。到目前为止,我一直在使用我的域凭据,但希望在服务器本身上使用 sql server 身份验证,但无论如何我都会收到 401 错误。

public byte[] GetReportBytes(string report, string parameterList)
    {
        string strReportUser = "sqlserveruser";
        string strReportUserPW = "password";
        //not used with sql?
        string strReportUserDomain = "domain";

        string sTargetURL = "reportserver?" +
                            "/folder/" + report + "&rs:Command=Render&rs:format=PDF&" + parameterList;

        HttpWebRequest req =
              (HttpWebRequest)WebRequest.Create(sTargetURL);
        req.PreAuthenticate = true;
        req.Credentials = new System.Net.NetworkCredential(
            strReportUser,
            strReportUserPW);

        HttpWebResponse HttpWResp = (HttpWebResponse)req.GetResponse();

        Stream fStream = HttpWResp.GetResponseStream();
        byte[] fileBytes = ReadFully(fStream);
        return fileBytes;
    }

这可能吗?

【问题讨论】:

    标签: asp.net reporting-services


    【解决方案1】:

    我认为您不能使用“sql server authentication”对 Reporting Services Web url 进行身份验证(至少是开箱即用的)。 (您的数据源可以,但这里我们讨论的是 SSRS 网址)。 “Sql Server 身份验证”未列为Authentication with the Report Server 支持的方法之一

    如果你想Configure Custom or Forms Authentication on the Report Server,你可以这样做

    您也可以Configure Basic Authentication on the Report Server,但即使这样也不使用“sql server authentication” - 请求会被传递给本地安全机构,最终可能会验证域凭据。

    在您的情况下,看起来您的 Web 应用程序本质上是充当代理(在某种意义上)-它将报告作为表示 pdf 的字节数组获取并返回,因此客户端浏览器实际上永远不会直接与 SSRS 通信。

    因此,我建议只保留 Windows 身份验证,并设置 SSRS 权限,以便您委托使用您的 asp.net 应用程序池的身份(并保持该应用程序池特定于您的特定应用程序)。这样,您无需在 Web 应用程序代码或配置中存储任何用户名或密码。

    要完成此操作,您还需要在 SSRS 中设置您的应用程序池身份用户至少具有“内容浏览器”权限。除非您的 iis 实例与您的报告服务服务器位于同一台计算机上,否则您将需要创建一个有限权限的域用户或镜像本地帐户以设置为您的应用程序池身份。 (或者,如果你真的想使用内置的 IIS ApplicationPoolIdentity 用户,你可以授予机器帐户的 SSRS 权限(例如 <domain>\<machinename>$),但这可能是不可取的,因为它授予更广泛的访问权限服务可以访问 SSRS)。

    如果您的 Web 应用程序使用表单身份验证,那么只需执行以下操作即可:

     req.Credentials = System.Net.CredentialCache.DefaultCredentials;
    

    但是,如果您对网站使用 windows 身份验证,则上述内容(如果记忆正确)将改为传递当前登录的 windows 用户的身份,而不是应用程序池身份,这可能不是什么你想要的。

    使用 SSRS 网络服务

    如果您愿意使用 SSRS Web 服务并通过在您的项目中使用“添加服务引用”生成一个肥皂客户端(您的示例代码没有这样做),您可以通过以下方式使用应用程序池身份进行身份验证执行以下操作:

     var soapClient = new ReportExecutionServiceSoapClient("ReportExecutionServiceSoap");
     soapClient.ClientCredentials.Windows.AllowedImpersonationLevel = 
                                System.Security.Principal.TokenImpersonationLevel.Delegation;
    

    我已经有一段时间没有这样做了,但是在使用“服务引用”时,您还需要确保 WCF 绑定是正确的。以下是我认为上次对我有用的方法:

    <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="ReportExecutionServiceSoap" allowCookies="true" maxReceivedMessageSize="5242880">
          <security mode="Transport">
            <transport clientCredentialType="Ntlm" proxyCredentialType="None" realm="" />
            <message clientCredentialType="Certificate" algorithmSuite="Default" />
          </security>
        </binding>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="https://theSsrsServer/ReportServer/ReportExecution2005.asmx" binding="basicHttpBinding" bindingConfiguration="ReportExecutionServiceSoap" contract="ReportService.ReportExecutionServiceSoap" name="ReportExecutionServiceSoap" />
    </client>
    

    【讨论】:

      【解决方案2】:

      不,这是不可能的。使用 Windows 凭据。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-03-09
        • 2015-11-15
        • 2013-09-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多