问题
I'm getting an 401 unauthorized error when using the ReportViewer on my test server. On my local environment (with the configurations pointed to the test server), I'm able to connect without a problem. I've tried looking the following solutions but with no luck. One two three
The authentication mode I am using is Windows and while my windows credentials I have access to the report server, I'm still unable to connect.
In my web.config
<system.web>
<customErrors mode="Off" />
<authentication mode="Windows" />
<authorization>
<deny users="?" />
</authorization>
...
My controller
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);
}
So that I may pinpoint the error, how and where can I see the user the my code is trying to authenticate with? I checked the exception but all the information I get is unauthorized, without telling my the user that is being used.
回答1:
I was able to figure out the answer and more importantly how to resolve the issue causing the 401 error.
First to answer my question, I was able to figure out the user by inspecting
System.Security.Principal.WindowsIdentity.GetCurrent().Name
When running the app in my local environment (the report server was pointed to the test url), it was using Windows login. Under the test server, it is using IIS APPPOOL
. I tried setting the report server credentials manually but with no success.
ReportViewer rv;
rv.ServerReport.ReportServerCredentials = new ReportServerCredentials("userName", "password", "domain");
However, I noticed by inspecting IIS manager where the login was coming from.
When I changed the identity to a NetworkService
, the application was able to access the report server correctly.
来源:https://stackoverflow.com/questions/46569291/reportviewer-error-401-view-user-logging-in