tags:

views:

439

answers:

1

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

A: 

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