ReportViewer错误401查看用户登录

在我的测试服务器上使用ReportViewer时,我收到了401未经授权的错误。 在我的本地环境中(配置指向测试服务器),我能够毫无问题地连接。 我试过看下面的解决方案,但没有运气。 一 二三

我使用的身份validation模式是Windows,而我的Windows凭据我可以访问报表服务器,我仍然无法连接。

在我的web.config中

      ... 

我的控制器

 private ReportViewer _reportViewer; public ReportController() { _reportViewer = new ReportViewer(); _reportViewer.ProcessingMode = ProcessingMode.Remote; _reportViewer.SizeToReportContent = false; _reportViewer.Width = Unit.Percentage(100); _reportViewer.Height = Unit.Pixel(893); string RptServerURL = ConfigurationManager.AppSettings["MyReportServerUrl"]; _reportViewer.ServerReport.ReportServerUrl = new Uri(RptServerURL); } 

因此,我可以查明错误,我如何以及在哪里可以看到我的代码尝试进行身份validation的用户? 我检查了exception,但我得到的所有信息都是未经授权的,没有告诉我的用户正在使用。

我能够找到答案,更重要的是如何解决导致401错误的问题。

首先回答我的问题,我能够通过检查找出用户

 System.Security.Principal.WindowsIdentity.GetCurrent().Name 

在我的本地环境中运行应用程序时(报表服务器指向测试URL),它正在使用Windows登录。 在测试服务器下,它使用IIS APPPOOL 。 我尝试手动设置报表服务器凭据但没有成功。

 ReportViewer rv; rv.ServerReport.ReportServerCredentials = new ReportServerCredentials("userName", "password", "domain"); 

但是,我注意到通过检查IIS管理器登录的来源。

在此处输入图像描述

当我将标识更改为NetworkService ,应用程序能够正确访问报表服务器。