我在SQL2005报告服务器上保存了一份报告,我想返回此报告的呈现PDF。我在使用本地* .rdlc文件(and I've blogged about it)时已经想到了这一点,但是当* .rdl驻留在报告服务器上时却没有。我在行...
收到 401 Not Authorized 错误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);
}
}
您可能需要了解的其他事项......
http://localhost:devport
)中运行时可以正常工作,在我的开发框(http://localhost/myApplication
)上运行时可以正常工作 。在我们的测试或生产服务器上运行时不起作用。我做错了什么?它是服务器设置吗?是代码吗?是web.config吗?
答案 0 :(得分:6)
我们终于弄明白了这个问题。我们的网络管理员已禁用双跳,因此当模拟正确连接为domain\jmeyer
时,应用程序仍在尝试使用domain\web01$
连接到SRS框。为什么这样设置?因为双跳是一个巨大的安全漏洞。 (或者有人告诉我。这听起来像是你在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") ; }
}
}
以上是您可以在整个互联网上找到的经典示例解决方案。
答案 1 :(得分:2)
允许“双跳” - 开始Kerberos身份验证...(只要它正常工作!)