Udostępnij przez


IntranetZoneCredentialPolicy.ShouldSendCredential Metoda

Definicja

Zwraca wartość wskazującą Boolean , czy poświadczenia klienta są wysyłane z żądaniem zasobu, który został wykonany przy użyciu polecenia WebRequest.

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

Parametry

challengeUri
Uri

Element Uri , który otrzyma żądanie.

request
WebRequest

Obiekt WebRequest reprezentujący żądany zasób.

credential
NetworkCredential

Element NetworkCredential , który zostanie wysłany z żądaniem, jeśli ta metoda zwróci wartość true.

authModule
IAuthenticationModule

To IAuthenticationModule spowoduje przeprowadzenie uwierzytelniania, jeśli jest wymagane uwierzytelnianie.

Zwraca

true jeśli żądany zasób znajduje się w tej samej domenie co klient wysyłający żądanie; w przeciwnym razie , false.

Implementuje

Przykłady

W poniższym przykładzie kodu pokazano wyprowadzanie z IntranetZoneCredentialPolicy metody , aby umożliwić wysyłanie poświadczeń dla żądań korzystających z protokołu HTTPS (Secure Hypertext Transfer Protocol) z uwierzytelnianiem podstawowym. Przy użyciu protokołu HTTPS i uwierzytelniania podstawowego hasło użytkownika jest szyfrowane przed wysłaniem za pośrednictwem sieci.

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

Uwagi

Aplikacje nie wywołają tej metody bezpośrednio; jest wywoływana przez serwer IAuthenticationModule , który jest odpowiedzialny za przeprowadzanie uwierzytelniania za pomocą serwera. Jeśli ta metoda zwróci falsewartość , IAuthenticationModule klient nie zostanie uwierzytelniony na serwerze.

Ta metoda jest wywoływana tylko w przypadku żądań, które określają poświadczenia lub używają obiektu określającego WebProxy poświadczenia.

Dotyczy