IReportServerCredentials 인터페이스

응용 프로그램이 Reporting Services 보고서 서버에 연결하기 위한 자격 증명을 제공할 수 있도록 합니다.

네임스페이스:  Microsoft.Reporting.WebForms
어셈블리:  Microsoft.ReportViewer.WebForms(Microsoft.ReportViewer.WebForms.dll)

구문

‘선언
Public Interface IReportServerCredentials
‘사용 방법
Dim instance As IReportServerCredentials
public interface IReportServerCredentials
public interface class IReportServerCredentials
type IReportServerCredentials =  interface end
public interface IReportServerCredentials

IReportServerCredentials 유형에서 다음 멤버를 표시합니다.

속성

  이름 설명
공용 속성 ImpersonationUser ReportViewer 컨트롤이 보고서 서버에 연결할 때 가장할 사용자의 System.Security.Principal.WindowsIdentity를 가져오거나 설정합니다.
공용 속성 NetworkCredentials 보고서 서버 인증에 사용되는 네트워크 자격 증명을 가져오거나 설정합니다.

맨 위로 이동

메서드

  이름 설명
공용 메서드 GetFormsCredentials 폼 인증용으로 구성된 보고서 서버 연결에 사용되는 정보를 제공합니다.

맨 위로 이동

주의

IReportServerCredentials 인터페이스를 구현할 때는 ReportViewer 컨트롤이 개체 인스턴스를 ASP.NET 세션에 저장한다는 사실을 알아야 합니다. 서버의 ASP.NET 세션이 Reporting Services에서처럼 Out-of-process로 저장되는 경우 클래스가 직렬화되어 저장될 수 있도록 Serializable로 표시되어야 합니다.

필수 사항은 아니지만 IReportServerCredentials 인터페이스를 상태 비저장 개체로 구현하는 것도 좋습니다. 이렇게 하면 개체를 직렬화할 때 사용자 이름 및 암호와 같은 자격 증명 정보가 저장되지 않습니다.

ReportViewer 컨트롤에 자격 증명을 지정하는 방법은 ReportViewer 웹 서버 컨트롤에 대한 연결 및 자격 증명 지정을 참조하십시오.

다음 예에서는 직렬화되어 저장될 수 있도록 Serializable로 표시된 IReportServerCredentials의 구현을 제공합니다. 자격 증명 정보는 Web.config 파일에서 검색됩니다. 이 구현은 모든 클라이언트 요청에 대해 같은 자격 증명을 사용하여 보고서 서버에 연결합니다.

이 예를 사용하려면 응용 프로그램의 Web.config 파일에 있는 appSettings 블록에 MyReportViewerUser, MyReportViewerPassword 및 MyReportViewerDomain의 세 가지 키 값 쌍을 추가해야 합니다. 이러한 값은 보고서 서버 연결에 사용되는 사용자 이름, 암호 및 도메인에 해당합니다.

using System;
using System.Data;
using System.Configuration;
using System.Net;
using System.Security.Principal;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Microsoft.Reporting.WebForms;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Init(object sender, EventArgs e)
    {
        ReportViewer1.ServerReport.ReportServerCredentials = 
            new MyReportServerCredentials();
    }
}

[Serializable]
public sealed class MyReportServerCredentials : 
    IReportServerCredentials
{
    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;
    }
}
Imports System.Net
Imports System.Security.Principal
Imports Microsoft.Reporting.WebForms

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Init(ByVal sender As Object, _
                            ByVal e As System.EventArgs) _
                            Handles Me.Init

        ReportViewer1.ServerReport.ReportServerCredentials = _
            New MyReportServerCredentials()

    End Sub

End Class

<Serializable()> _
Public NotInheritable Class MyReportServerCredentials
    Implements IReportServerCredentials

    Public ReadOnly Property ImpersonationUser() As WindowsIdentity _
            Implements IReportServerCredentials.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 IReportServerCredentials.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 IReportServerCredentials.GetFormsCredentials

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

        'Not using form credentials
        Return False

    End Function

End Class

참고 항목

참조

Microsoft.Reporting.WebForms 네임스페이스

IReportServerConnection2