sql >> Database teknologi >  >> RDS >> Sqlserver

Anmodningen mislykkedes med HTTP-status 401:Uautoriseret I SSRS

Jeg får også den samme fejl,

The request failed with HTTP status 401: Unauthorized.

Lad mig dele, hvad jeg prøvede, og det fungerer fint nu.

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

Inde i page_load begivenhed,

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

Dette virkede for mig!



  1. Oracle SQL, sammenkæd flere kolonner + tilføj tekst

  2. RowGen v3 automatiserer generering af databasetestdata

  3. Sådan begrænser du resultater i T-SQL

  4. T-SQL Spring over Tag lagret procedure