【发布时间】:2010-11-29 04:22:37
【问题描述】:
我在 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);
}
}
你可能需要知道的其他事情......
- 这是在 Intranet 上运行的,并且模拟已打开。
- 日志记录表明模拟用户设置正确。
- 在 Visual Studio (
http://localhost:devport) 中运行时确实有效,在我的开发箱 (http://localhost/myApplication) 上运行时确实有效。在我们的测试或生产服务器上运行时,它不起作用。 - 我已经尝试过在 web.config 中使用和不使用 system.net.defaultProxy 设置的解决方案。两者都不起作用。
我做错了什么?是服务器设置吗?是代码吗?是 web.config 吗?
【问题讨论】:
-
模拟用户是否有权访问报表服务器——尤其是那个报表?
-
您是否尝试过在您的开发机器 (localhost) 上以模拟用户身份运行 IIS,以更接近地模拟您的测试服务器上发生的情况?这听起来像是您的模拟用户对报告服务器或报告服务器数据库的完全权限问题。我假设模拟用户是域帐户。
-
@NYSystemsAnalyst - 是的,模拟用户有权访问报表服务器上的相应目录。
标签: asp.net reporting-services http-status-code-401