NetworkCredentials with ReportViewer (web) control

I have my web application, which allows the user to view the reports in ReportViewer (WebForm) control on internet. The problem is in setting ReportServerCredentials. As against WinForm I cannt use it like below.

ReportViewer1.ServerReport.ReportServerCredentials = New System.Net.NetworkCredential(sUserId, sPwd, sDomain)

In the above, I specify the encrypted value of userid and pwd and domain in the config file and decrypt before doing the above.

But, the same doesnt work with WebForm control. My implementation procedure should be same in webform application. I have read a lot about it like ImpersonateUser, FormsAuthentication.... etc. But I want to know..

1. I am using Sept CTP, is this been addressed in RTM

2. How do I make use of NetworkCredentials (I already have userid, pwd and domain name ready... in the config file), is there any sample code

3. Are there any issues following this method

Thanks in advance.



Answer this question

NetworkCredentials with ReportViewer (web) control

  • Erwin van Hunen

    Thanks Brian,

    I have got the solution by doing the following. Not sure if am correct

    public class ReportServerCredentials: Microsoft.Reporting.WebForms.IReportServerCredentials

    {

    private string strUserName;

    private string strPassword;

    private string strDomain;

    public ReportServerCredentials(string sUserName, string sPassword, string sDomain)

    {

    //Set the values in local variables.

    strUserName = sUserName;

    strPassword = sPassword;

    strDomain = sDomain;

    }

    #region IReportServerCredentials Members

    public bool GetFormsCredentials(out System.Net.Cookie authCookie, out string userName, out string password, out string authority)

    {

    authCookie = null;

    userName = password = authority = null;

    return false;

    }

    public System.Security.Principal.WindowsIdentity ImpersonationUser

    {

    get { return null; }

    }

    public System.Net.ICredentials NetworkCredentials

    {

    get { return new System.Net.NetworkCredential(strUserName, strPassword, strDomain); }

    }

    #endregion

    }

    and using the following line

    ReportViewer1.ServerReport.ReportServerCredentials = _

    New ReportServerCredentials(sNetworkUserId, sNetworkPwd, sNetworkDomain)

    May be this will help others as well.


  • Darrel Miller

    Supplying custom credentials is a little more complicated in webforms. The main reason behind this is because the credentials need to be available even after the aspx page has finished executing, to retrieve asynchronous images from the report server, for example.

    To supply credentials, you need to implement IReportServerCredentials on a serializable object (depending on your session state settings) and pass that to ReportViewer.ServerReport.ReportServerCredentials.


  • NetworkCredentials with ReportViewer (web) control