ICredentials.GetCredential(Uri, String) ICredentials.GetCredential(Uri, String) ICredentials.GetCredential(Uri, String) Method

Definition

Gibt ein NetworkCredential-Objekt zurück, das dem angegebenen URI und Authentifizierungstyp zugeordnet ist.Returns a NetworkCredential object that is associated with the specified URI, and authentication type.

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

Parameter

uri
Uri Uri Uri

Der Uri, für den der Client die Authentifizierung bereitstellt.The Uri that the client is providing authentication for.

authType
String String String

Der Authentifizierungstyp entsprechend der Definition in der AuthenticationType-Eigenschaft.The type of authentication, as defined in the AuthenticationType property.

Gibt zurück

Die dem angegebenen URI und dem Authentifizierungstyp zugeordneten NetworkCredential oder null, wenn keine Anmeldeinformationen verfügbar sind.The NetworkCredential that is associated with the specified URI and authentication type, or, if no credentials are available, null.

Beispiele

Die folgenden Anwendungsbereiche GetCredential zum Abrufen einer NetworkCredential Instanz.The following uses GetCredential to retrieve a NetworkCredential instance.

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 '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

Hinweise

Die GetCredential Methode gibt eine NetworkCredential -Instanz, die Anmeldeinformationen enthält, die mit dem angegebenen URI und die Autorisierung Schema verknüpft sind.The GetCredential method returns a NetworkCredential instance that contains the credentials that are associated with the specified URI and authorization scheme. Wenn keine Anmeldeinformationen verfügbar sind, sind die GetCredential Methodenrückgabe null.When no credentials are available, the GetCredential method returns null.

Gilt für: