IReportServerConnection2 Interface

 

Provides report server connection information when the ReportViewer Web forms control is used with no session state.

Namespace:   Microsoft.Reporting.WebForms
Assembly:  Microsoft.ReportViewer.WebForms (in Microsoft.ReportViewer.WebForms.dll)

public interface IReportServerConnection2 : IReportServerConnection, 
	IReportServerCredentials

NameDescription
System_CAPS_pubpropertyCookies

Gets a collection of custom cookies to send to the report server.

System_CAPS_pubpropertyHeaders

Gets a collection of custom headers to send to the report server.

System_CAPS_pubpropertyImpersonationUser

Gets or sets the System.Security.Principal.WindowsIdentity of the user to impersonate when the ReportViewer control connects to a report server.(Inherited from IReportServerCredentials.)

System_CAPS_pubpropertyNetworkCredentials

Gets or sets the network credentials that are used for authentication with the report server.(Inherited from IReportServerCredentials.)

System_CAPS_pubpropertyReportServerUrl

Returns the URL of the report server.(Inherited from IReportServerConnection.)

System_CAPS_pubpropertyTimeout

Gets the number of milliseconds to wait for server communications.(Inherited from IReportServerConnection.)

NameDescription
System_CAPS_pubmethodGetFormsCredentials(Cookie, String, String, String)

Provides information that will be used to connect to the report server that is configured for forms authentication.(Inherited from IReportServerCredentials.)

When an implementation of the IReportServerConnection2 interface is specified in the Web.config settings, the values for the ReportServerUrl, Timeout, Cookies and Headers properties on the ServerReport instance will not be used. The values provided by the IReportServerConnection2 implementation will be used instead. In addition to these properties, the credential information that is provided by the IReportServerConnection2 implementation will also be used.

For more information about how to specify connections with the ReportViewer control, see Specifying Connections and Credentials for the ReportViewer Web Server Control.

For more information about the ReportViewerServerConnection Web.config setting, see Web.config Settings for ReportViewer.

Legacy Code Example

The following example provides an implementation of IReportServerConnection2 interface that retrieves the report server URL and credential information from the Web.config file.

Before using the example, five key/value pairs must be added to the application's Web.config file in the appSettings block: ReportViewerServerConnection, MyReportViewerUser, MyReportViewerPassword, MyReportViewerDomain, and MyReportServerUrl, where the values correspond to the user name, password, and domain for connecting to the report server, and the URL of the report server. The ReportViewerServerConnection value must be set to the fully qualified assembly name for the implementation of the IReportServerConnection2 class.

For more information about the Web.config ReportViewerServerConnection setting, see Web.config Settings for ReportViewer.

public sealed class MyReportServerConnection : IReportServerConnection2
{
    public WindowsIdentity ImpersonationUser
    {
        get
        {
            // Use the default Windows user.  Credentials will be
            // provided by the NetworkCredentials property.
            return null;
        }
    }

    public ICredentials NetworkCredentials
    {
        get
        {
            // Read the user information from the web.config file.  
            // By reading the information on demand instead of 
            // storing it, the credentials will not be stored in 
            // session, reducing the vulnerable surface area to the
            // web.config file, which can be secured with an ACL.

            // User name
            string userName =
                ConfigurationManager.AppSettings
                    ["MyReportViewerUser"];

            if (string.IsNullOrEmpty(userName))
                throw new Exception(
                    "Missing user name from Web.config file");

            // Password
            string password =
                ConfigurationManager.AppSettings
                    ["MyReportViewerPassword"];

            if (string.IsNullOrEmpty(password))
                throw new Exception(
                    "Missing password from Web.config file");

            // Domain
            string domain =
                ConfigurationManager.AppSettings
                    ["MyReportViewerDomain"];

            if (string.IsNullOrEmpty(domain))
                throw new Exception(
                    "Missing domain from Web.config file");

            return new NetworkCredential(userName, password, domain);
        }
    }

    public bool GetFormsCredentials(out Cookie authCookie,
                out string userName, out string password,
                out string authority)
    {
        authCookie = null;
        userName = null;
        password = null;
        authority = null;

        // Not using form credentials
        return false;
    }

    public Uri ReportServerUrl
    {
        get
        {
            string url = 
                ConfigurationManager.AppSettings[
                    "MyReportServerUrl"];

            if (string.IsNullOrEmpty(url))
                throw new Exception(
                    "Missing url from the Web.config file");

            return new Uri(url);
        }
    }

    public int Timeout
    {
        get
        {
            return 60000; // 60 seconds
        }
    }

    public IEnumerable<Cookie> Cookies
    {
        get
        {
            // No custom cookies
            return null;
        }
    }

    public IEnumerable<string> Headers
    {
        get
        {
            // No custom headers
            return null;
        }
    }
}
Return to top
Show: