다음을 통해 공유


ICredentials 인터페이스

웹 클라이언트 인증을 위한 자격 증명을 검색할 수 있는 기본 인증 인터페이스를 제공합니다.

네임스페이스: System.Net
어셈블리: System(system.dll)

구문

‘선언
Public Interface ICredentials
‘사용 방법
Dim instance As ICredentials
public interface ICredentials
public interface class ICredentials
public interface ICredentials
public interface ICredentials

설명

ICredentials 인터페이스는 응용 프로그램에 네트워크 인증서를 제공하는 개체에 GetCredential 메서드를 제공합니다.

예제

다음 예제에서는 ICredentials 인터페이스를 사용하는 방법을 보여 줍니다.

       
Class CredentialInfo
    Public uriObj As Uri
    Public authenticationType As [String]
    Public networkCredentialObj As NetworkCredential
    
    
    Public Sub New(uriObj As Uri, authenticationType As [String], networkCredentialObj As NetworkCredential)
        Me.uriObj = uriObj
        Me.authenticationType = authenticationType
        Me.networkCredentialObj = networkCredentialObj
    End Sub 'New
End Class 'CredentialInfo

Private arrayListObj As ArrayList


Public Sub New()
    arrayListObj = New ArrayList()
End Sub 'New


Public Sub Add(uriObj As Uri, authenticationType As [String], credential As NetworkCredential)
    ' adds a 'CredentialInfo' object into a list
    arrayListObj.Add(New CredentialInfo(uriObj, authenticationType, credential))
End Sub 'Add

' Remove the 'CredentialInfo' object from the list which matches to the given 'Uri' and 'AuthenticationType'
Public Sub Remove(uriObj As Uri, authenticationType As [String])
    Dim index As Integer
    For index = 0 To arrayListObj.Count - 1
        Dim credentialInfo As CredentialInfo = CType(arrayListObj(index), CredentialInfo)
        If uriObj.Equals(credentialInfo.uriObj) And authenticationType.Equals(credentialInfo.authenticationType) Then
            arrayListObj.RemoveAt(index)
        End If
    Next index
End Sub 'Remove

Public Function GetCredential(uriObj As Uri, authenticationType As [String]) As NetworkCredential  Implements ICredentials.GetCredential
    Dim index As Integer
    For index = 0 To arrayListObj.Count - 1
        Dim credentialInfoObj As CredentialInfo = CType(arrayListObj(index), CredentialInfo)
        If uriObj.Equals(credentialInfoObj.uriObj) And authenticationType.Equals(credentialInfoObj.authenticationType) Then
            Return credentialInfoObj.networkCredentialObj
        End If
    Next index
    Return Nothing
End Function 'GetCredential
class CredentialList : ICredentials
{
    class CredentialInfo
    {
        public Uri uriObj;
        public String authenticationType;
        public NetworkCredential networkCredentialObj;
  
        public CredentialInfo(Uri uriObj, String authenticationType, NetworkCredential networkCredentialObj)
        {
            this.uriObj = uriObj;
            this.authenticationType = authenticationType;
            this.networkCredentialObj = networkCredentialObj;
        }
    }

    private ArrayList arrayListObj;

    public CredentialList()
    {
        arrayListObj = new ArrayList();
    }

    public void Add (Uri uriObj, String authenticationType, NetworkCredential credential)
    {
        // Add a 'CredentialInfo' object into a list.
        arrayListObj.Add (new CredentialInfo(uriObj, authenticationType, credential));      
    }
    // Remove the 'CredentialInfo' object from the list that matches to the given 'Uri' and 'AuthenticationType'
    public void Remove (Uri uriObj, String authenticationType)
    {
        for(int index=0;index < arrayListObj.Count; index++)
        {
            CredentialInfo credentialInfo = (CredentialInfo)arrayListObj[index];
            if(uriObj.Equals(credentialInfo.uriObj)&& authenticationType.Equals(credentialInfo.authenticationType))
                arrayListObj.RemoveAt(index);
        }
    }
    public NetworkCredential GetCredential (Uri uriObj, String authenticationType)
    {
        for(int index=0;index < arrayListObj.Count; index++)
        {
            CredentialInfo credentialInfoObj = (CredentialInfo)arrayListObj[index];
            if(uriObj.Equals(credentialInfoObj.uriObj) && authenticationType.Equals(credentialInfoObj.authenticationType))
                return credentialInfoObj.networkCredentialObj;
        }
        return null;
    }
};
ref class CredentialList: public ICredentials
{
private:
   ref class CredentialInfo
   {
   public:
      Uri^ uriObj;
      String^ authenticationType;
      NetworkCredential^ networkCredentialObj;
      CredentialInfo( Uri^ uriObj, String^ authenticationType, NetworkCredential^ networkCredentialObj )
      {
         this->uriObj = uriObj;
         this->authenticationType = authenticationType;
         this->networkCredentialObj = networkCredentialObj;
      }
   };

   ArrayList^ arrayListObj;

public:
   CredentialList()
   {
      arrayListObj = gcnew ArrayList;
   }

   void Add( Uri^ uriObj, String^ authenticationType, NetworkCredential^ credential )
   {
      
      // Add a 'CredentialInfo' object into a list.
      arrayListObj->Add( gcnew CredentialInfo( uriObj,authenticationType,credential ) );
   }

   // Remove the 'CredentialInfo' object from the list that matches to the given 'Uri' and 'AuthenticationType'
   void Remove( Uri^ uriObj, String^ authenticationType )
   {
      for ( int index = 0; index < arrayListObj->Count; index++ )
      {
         CredentialInfo^ credentialInfo = dynamic_cast<CredentialInfo^>(arrayListObj[ index ]);
         if ( uriObj->Equals( credentialInfo->uriObj ) && authenticationType->Equals( credentialInfo->authenticationType ) )
                  arrayListObj->RemoveAt( index );
      }
   }

   virtual NetworkCredential^ GetCredential( Uri^ uriObj, String^ authenticationType )
   {
      for ( int index = 0; index < arrayListObj->Count; index++ )
      {
         CredentialInfo^ credentialInfoObj = dynamic_cast<CredentialInfo^>(arrayListObj[ index ]);
         if ( uriObj->Equals( credentialInfoObj->uriObj ) && authenticationType->Equals( credentialInfoObj->authenticationType ) )
                  return credentialInfoObj->networkCredentialObj;
      }
      return nullptr;
   }
};
class CredentialList implements ICredentials
{
    class CredentialInfo
    {
        public Uri uriObj;
        public String authenticationType;
        public NetworkCredential networkCredentialObj;

        public CredentialInfo(Uri uriObj, String authenticationType, 
            NetworkCredential networkCredentialObj)
        {
            this.uriObj = uriObj;
            this.authenticationType = authenticationType;
            this.networkCredentialObj = networkCredentialObj;
        } //CredentialInfo
    } //CredentialInfo

    private ArrayList arrayListObj;

    public CredentialList()
    {
        arrayListObj = new ArrayList();
    } //CredentialList

    public void Add(Uri uriObj, String authenticationType, 
        NetworkCredential credential)
    {
        // Add a 'CredentialInfo' object into a list.
        arrayListObj.Add(new CredentialInfo(uriObj, 
            authenticationType, credential));
    } //Add

    // Remove the 'CredentialInfo' object from the list that matches to 
    // the given 'Uri' and 'AuthenticationType'
    public void Remove(Uri uriObj, String authenticationType)
    {
        for (int index = 0; index < arrayListObj.get_Count(); index++) {
            CredentialInfo credentialInfo = (CredentialInfo)
                arrayListObj.get_Item(index);

            if (uriObj.Equals(credentialInfo.uriObj) && 
                authenticationType.Equals(credentialInfo.authenticationType)) {
                arrayListObj.RemoveAt(index);
            }
        }
    } //Remove

    public NetworkCredential GetCredential(Uri uriObj, 
        String authenticationType)
    {
        for (int index = 0; index < arrayListObj.get_Count(); index++) {
            CredentialInfo credentialInfoObj = (CredentialInfo)
                arrayListObj.get_Item(index);

            if (uriObj.Equals(credentialInfoObj.uriObj) && 
                authenticationType.Equals(credentialInfoObj.
                authenticationType)) {
                return credentialInfoObj.networkCredentialObj;
            }
        }
        return null;
    } //GetCredential
} //CredentialList

플랫폼

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

2.0, 1.1, 1.0에서 지원

.NET Compact Framework

2.0, 1.0에서 지원

참고 항목

참조

ICredentials 멤버
System.Net 네임스페이스