Search code examples
asp.netrdl

Hardcode reporting services credentials to view reports on asp.net site without prompt


Can I provide somewhere credentials to use for viewing some report? It is a .rdl report viewed in reportViewer control on asp.net website.


Solution

  • You need to code the credentials into the ReportViewer control. Take a look at the following class:

       public class ReportCredentials : Microsoft.Reporting.WebForms.IReportServerCredentials
        {
            string _userName, _password, _domain;
            public ReportCredentials(string userName, string password, string domain)
            {
                _userName = userName;
                _password = password;
                _domain = domain;
            }
    
    
    
            public System.Security.Principal.WindowsIdentity ImpersonationUser
        {
            get
            {
                return null;
            }
        }
    
    
        public System.Net.ICredentials NetworkCredentials
        {
            get
            {
             return new System.Net.NetworkCredential(_userName, _password, _domain);
            }
        }
    
    
        public bool GetFormsCredentials(out System.Net.Cookie authCoki, out string userName, out string password, out string authority)
        {
            userName = _userName;
            password = _password;
            authority = _domain;
            authCoki = new System.Net.Cookie(".ASPXAUTH", ".ASPXAUTH", "/", "Domain");
            return true;
        }
    }