7

SQL2005レポートサーバーにレポートを保存しましたが、このレポートのレンダリングされたPDFを返したいと思います。ローカルの*.rdlcファイルを操作しているときにこれを理解しました(そしてそれについてブログに書いています)が、*。rdlがレポートサーバーにあるときはわかりません。行で401NotAuthorizedエラーが発生します...

reportViewer.ServerReport.SetParameters(reportDefinition.ReportParameters);

レポートのレンダリングに使用される方法は次のとおりです。

public byte[] Render(IReportDefinition reportDefinition)
{
    var reportViewer = new ReportViewer();
    byte[] renderedReport;
    try
    {
        var credentials = new WindowsImpersonationCredentials();
        reportViewer.ServerReport.ReportServerUrl = new Uri("http://myssrsbox", UrlKind.Absolute);
        reportViewer.ServerReport.ReportServerCredentials = credentials;
        reportViewer.ServerReport.ReportPath = reportDefinition.Path;
        // Exception is thrown on the following line...
        reportViewer.ServerReport.SetParameters(reportDefinition.ReportParameters);

        string mimeType;
        string encoding;
        string filenameExtension;
        string[] streams;
        Warning[] warnings;

        renderedReport = reportViewer.ServerReport.Render(reportDefinition.OutputType, reportDefinition.DeviceInfo, out mimeType, out encoding, out filenameExtension, out streams, out warnings);
    }
    catch (Exception ex)
    {
        // log the error...
        throw;
    }
    finally
    {
        reportViewer.Dispose();
    }
    return renderedReport;
}

もう1つ欠けているのは、WindowsImpersonationCredentialsクラスです。

public class WindowsImpersonationCredentials : IReportServerCredentials
{
    public bool GetFormsCredentials(out Cookie authCookie, out string userName, out string password, out string authority)
    {
        authCookie = null;
        userName = password = authority = null;
        return false;
    }

    public WindowsIdentity ImpersonationUser
    {
        get { return WindowsIdentity.GetCurrent(); }
    }

    public ICredentials NetworkCredentials
    {
        get { return null; }
    }

    public override string ToString()
    {
        return String.Format("WindowsIdentity: {0} ({1})", this.ImpersonationUser.Name, this.ImpersonationUser.User.Value);
    }
}

あなたが知る必要があるかもしれない他のこと...

  • これはイントラネット上で実行されており、偽装がオンになっています。
  • ロギングは、偽装ユーザーが正しく設定されていることを示しています。
  • これ、Visual Studio(http://localhost:devport)で実行している場合は機能し、開発ボックス(http://localhost/myApplication)で実行している場合は機能します。テストサーバーまたは本番サーバーで実行している場合は機能しません。
  • web.configのsystem.net.defaultProxy設定がある場合とない場合の両方で解決策を試しました。どちらも機能しませんでした。

私は何が間違っているのですか?サーバー設定ですか?コードですか?web.configですか?

4

2 に答える 2

6

私たちはついに問題を理解しました。ネットワーク管理者がダブルホッピングを無効にしているため、なりすましがとして正しく接続されている間domain\jmeyer、アプリケーションは。を使用してSRSボックスに接続しようとしましたdomain\web01$。なぜこのように設定されているのですか?ダブルホッピングは大きなセキュリティホールだからです。(またはそう言われました。これは、The Daily WTFで読むようなものですか?)

私たちの解決策は、汎用domain\ssrs_report_servicesユーザーを作成し、次のネットワーク資格情報を使用してそのユーザーに接続することでした。

public class CustomCredentials : IReportServerCredentials
{
    public bool GetFormsCredentials(out Cookie authCookie, out string userName, out string password, out string authority)
    {
        authCookie = null;
        userName = password = authority = null;
        return false;
    }

    public WindowsIdentity ImpersonationUser
    {
        get { return null; }
    }

    public ICredentials NetworkCredentials
    {
        get { return new NetworkCredential("ssrs_report_services", "password", "domain") ; }
    }    
}

上記は、インターネット全体で見つけることができる典型的なソリューションの例です。

于 2009-09-17T15:49:01.433 に答える
2

「ダブルホッピング」が許可されます-Kerberos認証でswith...(正しく機能している限り!)

于 2009-09-21T14:04:29.960 に答える