1

I am creating ASP.NET Core Web Application and I am using ReportViewer to view a report that is hosted on another server. I am trying to connect to the server but i get this error "The request failed with HTTP status 401: Unauthorized" and I don't understand how to change it. This is my code:

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;
        }
    }
}

I'm not sure where to look and what I'm doing wrong. Would appreciate the help as it would save me hours of stress. Thanks.

A. Savva
  • 632
  • 10
  • 30

0 Answers0