我正在创建ASP.NET核心Web应用程序,我正在使用ReportViewer查看托管在另一台服务器上的报告。我正在尝试连接到服务器,但我收到此错误"The request failed with HTTP status 401: Unauthorized"
,我不明白如何更改它。这是我的代码:
namespace ecc_web_page.Reports
{
public partial class ReportTemplate : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
try
{
String reportFolder = System.Configuration.ConfigurationManager.AppSettings["Report project"].ToString();
rvSiteMapping.Height = Unit.Pixel(Convert.ToInt32(Request["Height"]) - 58);
rvSiteMapping.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
rvSiteMapping.ServerReport.ReportServerUrl = new Uri("http://x.x.x.x/ReportServer_SQLEXPRESS"); // Add the Reporting Server URL
rvSiteMapping.ServerReport.ReportPath = String.Format("/{0}/{1}", reportFolder, Request["Standard Report"].ToString());
IReportServerCredentials irsc = new ReportServerCredentials("username", "pass", "");
rvSiteMapping.ServerReport.ReportServerCredentials = irsc;
rvSiteMapping.ServerReport.Refresh();
}
catch (Exception ex)
{
}
}
}
}
public class ReportServerCredentials : IReportServerCredentials
{
private string _userName;
private string _password;
private string _domain;
public ReportServerCredentials(string userName, string password, string domain)
{
_userName = userName;
_password = password;
_domain = domain;
}
public WindowsIdentity ImpersonationUser
{
get
{
// Use default identity.
return null;
}
}
public ICredentials NetworkCredentials
{
get
{
// Use default identity.
return new NetworkCredential(_userName, _password, _domain);
}
}
WindowsIdentity IReportServerCredentials.ImpersonationUser
{
get
{
throw new NotImplementedException();
}
}
ICredentials IReportServerCredentials.NetworkCredentials
{
get
{
throw new NotImplementedException();
}
}
public bool GetFormsCredentials(out Cookie authCookie, out string userName, out string password, out string authority)
{
// Do not use forms credentials to authenticate.
authCookie = null;
userName = password = authority = null;
return false;
}
}
}
我不确定在哪里看,我做错了什么。非常感谢帮助,因为它可以节省我几个小时的压力。感谢。