我有一个报告保存在一个SQL2005报告服务器,并且我希望返回呈现PDF这份报告。我已经想通了这一工作时与当地*.rdlc文件(文件和我的博客它),但不是当*.rdl驻留在报告所述服务器。我得到一个 401没有授权 错误的线...

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;
}

其他的事情,你们缺少的是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).它的 不工作 上运行时,我们测试或者生产服务器。
  • 我已经尝试解决方案具有和不具有系统。网。defaultProxy设置在网络。config。既不是工作。

我做错了什么?它是一个服务器上设置?是它的代码?是它的网络。config?

有帮助吗?

解决方案

我们终于找出问题。我们的网络管理员有残疾的双跳跃,因此,虽然该模拟是正确的连接作 domain\jmeyer, ,应用仍是尝试连接到的SRS盒 domain\web01$.为什么设置这样吗?因为双跳跃是一个巨大的安全漏洞。(或所以有人告诉我。这种声音不会喜欢的东西你会读 日。?)

我们的解决方案是建立一个通用的 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") ; }
    }    
}

上述就是经典的例子,解决就可以找到所有在互联网.

其他提示

"双跳频"是允许的-开关于Kerberos认证...(只要它工作正常!)

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top