IntranetZoneCredentialPolicy.ShouldSendCredential Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Returnerar en Boolean som anger om klientens autentiseringsuppgifter skickas med en begäran om en resurs som har gjorts med hjälp av 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
Parametrar
- request
- WebRequest
Det WebRequest som representerar den resurs som begärs.
- credential
- NetworkCredential
Det NetworkCredential som skickas med begäran om den här metoden returnerar true.
- authModule
- IAuthenticationModule
Det IAuthenticationModule som utför autentiseringen, om autentisering krävs.
Returer
trueom den begärda resursen finns i samma domän som klienten som skickar begäran. annars . false
Implementeringar
Exempel
Följande kodexempel visar härledning från IntranetZoneCredentialPolicy för att tillåta att autentiseringsuppgifter skickas för begäranden som använder HTTPS (Secure Hypertext Transfer Protocol) med grundläggande autentisering. Med hjälp av HTTPS och grundläggande autentisering krypteras användarlösenordet innan det skickas via nätverket.
// 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 )
{
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 )
{
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;
}
}
Kommentarer
Program anropar inte den här metoden direkt. den anropas av den IAuthenticationModule som ansvarar för att utföra autentisering med servern. Om den här metoden returnerar falseautentiserar IAuthenticationModule inte klienten till servern.
Den här metoden anropas endast för begäranden som anger autentiseringsuppgifter eller använder ett WebProxy objekt som anger autentiseringsuppgifter.