IntranetZoneCredentialPolicy.ShouldSendCredential Methode

Definition

Gibt einen Boolean zurück, der angibt, ob die Anmeldeinformationen des Clients mit einer Ressourcenanforderung gesendet werden, die anhand eines WebRequest erstellt wurde.

public:
 virtual bool ShouldSendCredential(Uri ^ challengeUri, System::Net::WebRequest ^ request, System::Net::NetworkCredential ^ credential, System::Net::IAuthenticationModule ^ authModule);
public virtual bool ShouldSendCredential (Uri challengeUri, System.Net.WebRequest request, System.Net.NetworkCredential credential, System.Net.IAuthenticationModule authModule);
abstract member ShouldSendCredential : Uri * System.Net.WebRequest * System.Net.NetworkCredential * System.Net.IAuthenticationModule -> bool
override this.ShouldSendCredential : Uri * System.Net.WebRequest * System.Net.NetworkCredential * System.Net.IAuthenticationModule -> bool
Public Overridable Function ShouldSendCredential (challengeUri As Uri, request As WebRequest, credential As NetworkCredential, authModule As IAuthenticationModule) As Boolean

Parameter

challengeUri
Uri

Der Uri, der die Anforderung erhalten soll.

request
WebRequest

Die WebRequest, die die angeforderte Ressource darstellt.

credential
NetworkCredential

Die NetworkCredential, die mit der Anforderung gesendet wird, wenn diese Methode true zurückgibt.

authModule
IAuthenticationModule

Das IAuthenticationModule, das die Authentifizierung durchführt, wenn eine Authentifizierung erforderlich ist.

Gibt zurück

true, wenn sich die angeforderte Ressource in derselben Domäne befindet wie der Client, der die Anforderung erstellt, andernfalls false.

Implementiert

Beispiele

Das folgende Codebeispiel veranschaulicht die Ableitung von IntranetZoneCredentialPolicy , um das Senden von Anmeldeinformationen für Anforderungen zuzulassen, die HTTPS (Secure Hypertext Transfer Protocol) mit Standardauthentifizierung verwenden. Mithilfe von HTTPS und Standardauthentifizierung wird das Benutzerkennwort verschlüsselt, bevor es über das Netzwerk gesendet wird.

// The following class allows credentials to be sent if they are for requests for resources
// in the same domain, or if the request uses the HTTPSscheme and basic authentication is 
// required.
public ref class HttpsBasicCredentialPolicy: public IntranetZoneCredentialPolicy
{
public:
   HttpsBasicCredentialPolicy(){}

   virtual bool ShouldSendCredential( Uri^ challengeUri, WebRequest^ request, NetworkCredential^ credential, IAuthenticationModule^ authModule ) override
   {
      Console::WriteLine( L"Checking custom credential policy for HTTPS and basic." );
      bool answer = IntranetZoneCredentialPolicy::ShouldSendCredential( challengeUri, request, credential, authModule );
      if ( answer == true )
      {
         Console::WriteLine( L"Sending credential for intranet resource." );
         return answer;
      }

      // Determine whether the base implementation returned false for basic and HTTPS.
      if ( request->RequestUri->Scheme == Uri::UriSchemeHttps && authModule->AuthenticationType->Equals( L"Basic" ) )
      {
         Console::WriteLine( L"Sending credential for HTTPS and basic." );
         return true;
      }

      return false;
   }
};
// The following class allows credentials to be sent if they are for requests for resources
// in the same domain, or if the request uses the HTTPSscheme and basic authentication is
// required.

       public class HttpsBasicCredentialPolicy: IntranetZoneCredentialPolicy
    {
        public HttpsBasicCredentialPolicy()
        {
        }

        public override bool ShouldSendCredential(Uri challengeUri,
            WebRequest request,
            NetworkCredential credential,
            IAuthenticationModule authModule)
        {
            Console.WriteLine("Checking custom credential policy for HTTPS and basic.");
            bool answer = base.ShouldSendCredential(challengeUri, request, credential, authModule);

            if (answer == true)
            {
                Console.WriteLine("Sending credential for intranet resource.");
                return answer;
            }
            // Determine whether the base implementation returned false for basic and HTTPS.
            if (request.RequestUri.Scheme == Uri.UriSchemeHttps &&
                authModule.AuthenticationType == "Basic")
            {
                Console.WriteLine("Sending credential for HTTPS and basic.");
                return true;
            }
            return false;
        }
    }

Hinweise

Anwendungen rufen diese Methode nicht direkt auf. Sie wird von der aufgerufen, die für die IAuthenticationModule Authentifizierung beim Server verantwortlich ist. Wenn diese Methode zurückgibt false, authentifiziert den IAuthenticationModule Client nicht beim Server.

Diese Methode wird nur für Anforderungen aufgerufen, die Anmeldeinformationen angeben oder ein WebProxy Objekt verwenden, das Anmeldeinformationen angibt.

Gilt für: