Partilhar via


Interface IReportServerConnection2

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 (em Microsoft.ReportViewer.WebForms.dll)

Sintaxe

'Declaração
Public Interface IReportServerConnection2 _
    Inherits IReportServerConnection, IReportServerCredentials
public interface IReportServerConnection2 : IReportServerConnection, 
    IReportServerCredentials
public interface class IReportServerConnection2 : IReportServerConnection, 
    IReportServerCredentials
type IReportServerConnection2 =  
    interface
        interface IReportServerConnection
        interface IReportServerCredentials
    end
public interface IReportServerConnection2 extends IReportServerConnection, IReportServerCredentials

O tipo IReportServerConnection2 expõe os membros a seguir.

Propriedades

  Nome Descrição
Propriedade pública Cookies Gets a collection of custom cookies to send to the report server.
Propriedade pública Headers Gets a collection of custom headers to send to the report server.
Propriedade pública ImpersonationUser Gets or sets the WindowsIdentity of the user to impersonate when the ReportViewer control connects to a report server. (Herdado de IReportServerCredentials.)
Propriedade pública NetworkCredentials Gets or sets the network credentials that are used for authentication with the report server. (Herdado de IReportServerCredentials.)
Propriedade pública ReportServerUrl Returns the URL of the report server. (Herdado de IReportServerConnection.)
Propriedade pública Timeout Gets the number of milliseconds to wait for server communications. (Herdado de IReportServerConnection.)

Superior

Métodos

  Nome Descrição
Método público GetFormsCredentials Provides information that will be used to connect to the report server that is configured for forms authentication. (Herdado de IReportServerCredentials.)

Superior

Comentários

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 Especificando conexões e credenciais para o Controle do Servidor Web do ReportViewer.

For more information about the ReportViewerServerConnection Web.config setting, see Configurações de Web.config para ReportViewer.

Exemplos

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 Configurações de Web.config para 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;
        }
    }
}
Public NotInheritable Class MyReportServerConnection
    Implements IReportServerConnection2

    Public ReadOnly Property ImpersonationUser() As WindowsIdentity _
            Implements IReportServerConnection2.ImpersonationUser
        Get

            'Use the default Windows user.  Credentials will be
            'provided by the NetworkCredentials property.
            Return Nothing

        End Get
    End Property

    Public ReadOnly Property NetworkCredentials() As ICredentials _
            Implements IReportServerConnection2.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
            Dim userName As String = _
                ConfigurationManager.AppSettings("MyReportViewerUser")

            If (String.IsNullOrEmpty(userName)) Then
                Throw New Exception("Missing user name from web.config file")
            End If

            'Password
            Dim password As String = _
                ConfigurationManager.AppSettings("MyReportViewerPassword")

            If (String.IsNullOrEmpty(password)) Then
                Throw New Exception("Missing password from web.config file")
            End If

            'Domain
            Dim domain As String = _
                ConfigurationManager.AppSettings("MyReportViewerDomain")

            If (String.IsNullOrEmpty(domain)) Then
                Throw New Exception("Missing domain from web.config file")
            End If

            Return New NetworkCredential(userName, password, domain)

        End Get
    End Property

    Public Function GetFormsCredentials(ByRef authCookie As Cookie, _
                                        ByRef userName As String, _
                                        ByRef password As String, _
                                        ByRef authority As String) _
                                        As Boolean _
            Implements IReportServerConnection2.GetFormsCredentials

        authCookie = Nothing
        userName = Nothing
        password = Nothing
        authority = Nothing

        'Not using form credentials
        Return False

    End Function

    Public ReadOnly Property ReportServerUrl() As Uri 
           Implements IReportServerConnection2.ReportServerUrl
        Get
            Dim url As String = ConfigurationManager.AppSettings("MyReportViewerUrl")
            If (String.IsNullOrEmpty(url)) Then
                Throw New Exception("Missing url from the web.config file")
            End If

            Return New Uri(url)

        End Get
    End Property

    Public ReadOnly Property Timeout() As Integer Implements IReportServerConnection2.Timeout
        Get
            Return 60000 '60 seconds
        End Get
    End Property

    Public ReadOnly Property Cookies() As IEnumerable(Of Cookie) Implements IReportServerConnection2.Cookies
        Get
            Return Nothing
        End Get
    End Property

    Public ReadOnly Property Headers() As IEnumerable(Of String) Implements IReportServerConnection2.Headers
        Get
            Return Nothing
        End Get
    End Property

End Class

Consulte também

Referência

Namespace Microsoft.Reporting.WebForms

IReportServerCredentials

Outros recursos

Configurações de Web.config para ReportViewer

Especificando conexões e credenciais para o Controle do Servidor Web do ReportViewer