ICredentials.GetCredential(Uri, String) 메서드

정의

지정된 URI 및 인증 형식과 관련된 NetworkCredential 개체를 반환합니다.

public:
 System::Net::NetworkCredential ^ GetCredential(Uri ^ uri, System::String ^ authType);
public System.Net.NetworkCredential GetCredential (Uri uri, string authType);
public System.Net.NetworkCredential? GetCredential (Uri uri, string authType);
abstract member GetCredential : Uri * string -> System.Net.NetworkCredential
Public Function GetCredential (uri As Uri, authType As String) As NetworkCredential

매개 변수

uri
Uri

클라이언트에서 인증을 제공하는 Uri입니다.

authType
String

AuthenticationType 속성에 정의된 것과 같은 인증 형식입니다.

반환

지정된 URI 및 인증 형식과 관련된 NetworkCredential입니다. 사용할 수 있는 자격 증명이 없으면 null입니다.

예제

다음은 를 사용하여 GetCredential instance 검색합니다 NetworkCredential .

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 : 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;
    }
};

 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
 End Class
 
 Private arrayListObj As ArrayList
 
 
 Public Sub New()
     arrayListObj = New ArrayList()
 End Sub
 
 
 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
 
 ' 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
 
 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

설명

메서드는 GetCredential 지정된 URI 및 권한 부여 체계와 연결된 자격 증명을 포함하는 instance 반환 NetworkCredential 합니다. 사용할 수 있는 자격 증명이 없으면 메서드는 를 GetCredential 반환합니다 null.

적용 대상