ReportViewer错误401查看用户登录
问题描述:
在我的测试服务器上使用ReportViewer时,出现401未经授权的错误。在我的本地环境中(配置指向测试服务器的配置),我可以无问题地进行连接。我试过看下面的解决方案,但没有运气。 OnetwothreeReportViewer错误401查看用户登录
我使用的身份验证模式是Windows,虽然我的Windows凭据可以访问报表服务器,但仍无法连接。
在我的web.config
<system.web>
<customErrors mode="Off" />
<authentication mode="Windows" />
<authorization>
<deny users="?" />
</authorization>
...
我控制器
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);
}
所以,我可以查明错误,如何和其中我可以看到我的代码试图用户通过身份验证?我检查了例外情况,但是我得到的所有信息都是未经授权的,没有告诉我正在使用的用户。
答
我能够找出答案,更重要的是如何解决导致401错误的问题。
首先回答我的问题,我可以通过检查
System.Security.Principal.WindowsIdentity.GetCurrent().Name
当我在本地环境中运行的应用程序(报表服务器中指出,测试URL)来找出用户,它是用Windows登录。在测试服务器下,它使用IIS APPPOOL
。我尝试手动设置报表服务器凭据,但没有成功。
ReportViewer rv;
rv.ServerReport.ReportServerCredentials = new ReportServerCredentials("userName", "password", "domain");
但是,我注意到通过检查IIS管理器登录是从哪里来的。
当我改变身份为NetworkService
,应用程序能够正确访问报表服务器。