sql >> Database >  >> RDS >> Sqlserver

Het verzoek is mislukt met HTTP-status 401:Ongeautoriseerd IN SSRS

Ik krijg ook dezelfde fout,

The request failed with HTTP status 401: Unauthorized.

Laat me delen wat ik heb geprobeerd en het werkt nu prima.

public class CustomSSRSCredentials : IReportServerCredentials
    {
        private string _SSRSUserName;
        private string _SSRSPassWord;
        private string _DomainName;

        public CustomSSRSCredentials(string UserName, string PassWord, string DomainName)
        {
            _SSRSUserName = UserName;
            _SSRSPassWord = PassWord;
            _DomainName = DomainName;
        }

        public System.Security.Principal.WindowsIdentity ImpersonationUser
        {
            get { return null; }
        }

        public ICredentials NetworkCredentials
        {
            get { return new NetworkCredential(_SSRSUserName, _SSRSPassWord, _DomainName); }
        }

        public bool GetFormsCredentials(out Cookie authCookie, out string user,
         out string password, out string authority)
        {
            authCookie = null;
            user = password = authority = null;
            return false;
        }
    }

Binnen page_load evenement,

if (!Page.IsPostBack)
{
    ReportViewer1.ProcessingMode = ProcessingMode.Remote;
    IReportServerCredentials ssrscredentials = new CustomSSRSCredentials("MyUserName", "MyPassword", "ServerName");
    ServerReport serverReport = ReportViewer1.ServerReport;
    ReportViewer1.ServerReport.ReportServerCredentials = ssrscredentials;
    serverReport.ReportServerUrl = new Uri("ReportPathKey");
    serverReport.ReportPath = "/Reports/MyReport";
    serverReport.Refresh();
}

Dit werkte voor mij!



  1. SQL Server 2016:een tabel maken

  2. Waarom (en hoe) kolommen splitsen met master..spt_values?

  3. Interne SQL Server:Plan Caching Pt. I – Plannen hergebruiken

  4. MariaDB LOCALTIMESTAMP() uitgelegd