为什么我尝试使用 URL 访问权限下载 SSRS 报告时得到 500?

Why do I get a 500 when trying to download an SSRS report using URL access?

我有一份似乎工作正常的报告,但是当我尝试在我的 asp.net MVC 应用程序中下载它时,我得到了 500。我只是想使用 [= 下载它的 pdf 版本22=] 访问。为此,我执行以下操作:

WebClient client = new WebClient();
NetworkCredential nwc = new NetworkCredential(ConfigurationManager.AppSettings["SSRSUserName"], ConfigurationManager.AppSettings["SSRSPassword"]);
client.Credentials = nwc;
string paramList = "&OrderId=" + orderId;

string reportURL = ConfigurationManager.AppSettings["SSRSBaseUrl"] +
            ConfigurationManager.AppSettings["SSRSReport"] + 
            "&rs:Command=Render&rs:Format=PDF" +
            paramList;
try 
{
     byte[] reportBytes = client.DownloadData(reportURL);
}

为了验证我的报告是否正常工作,我获取了生成的报告URL 字符串,将其放入浏览器中,果然我的报告已完美下载。

有人知道为什么我会在我的应用程序中获得 500,但 pdf 可以在我的应用程序之外使用相同的 URL 下载得很好吗?我缺少他们的某些配置吗?

服务器版本是SQLServer 2016

总结讨论和解决方案,通过为 WebClient 设置 属性 UseDefaultCredentials = true 使用默认凭据解决了一般的 500 内部服务器错误。

由于您安装的是 post SQL Server 2008,身份验证请求由 Reporting Services 实例在内部处理。

In previous versions of Reporting Services, all authentication support was provided by IIS. Starting with the SQL Server 2008 release, IIS is no longer used. Reporting Services handles all authentication requests internally.

默认情况下,Reports Server 使用依赖于 Windows 集成身份验证的身份验证方法:Authentication with the Report Server 中提到的协商和 NTLM。

由于本例中的 Reports Server 使用以下一种或所有身份验证方法:协商、NTLM 和 Kerberos,并且这不是 ASP.NET 应用程序,因此需要使用默认凭据,如 DefaultCredentials:

The DefaultCredentials property applies only to NTLM, negotiate, and Kerberos-based authentication.

DefaultCredentials represents the system credentials for the current security context in which the application is running. For a client-side application, these are usually the Windows credentials (user name, password, and domain) of the user running the application. For ASP.NET applications, the default credentials are the user credentials of the logged-in user, or the user being impersonated.

这就是为什么您可以在浏览器中通过 URL 访问报表查看器,但不能在您的应用程序中访问。