Defines the credential policy to be used for resource requests that are made using WebRequest and its derived classes.
Assembly: System (in System.dll)
Thetype exposes the following members.
The credential policy determines whether to send credentials when sending a WebRequest for a network resource, such as the content of a Web page. If credentials are sent, servers that require client authentication can attempt to authenticate the client when the request is received instead of sending a response that indicates that the client's credentials are required. While this saves a round trip to the server, this performance gain must be balanced against the security risk inherent in sending credentials across the network. When the destination server does not require client authentication, it is best not to send credentials.
policies are invoked only if the WebRequest or the WebProxy that is associated with the request has credentials that are not Nothing. Setting this policy has no effect on requests that do not specify credentials.
Use the AuthenticationManager.CredentialPolicy property to set an policy. The IAuthenticationModule that handles authentication for the request will invoke the ShouldSendCredential method before performing the authentication. If the method returns false, authentication is not performed.
An policy affects all instances of WebRequest with non-null credentials in the current application domain. The policy cannot be overridden on individual requests.
The following code example shows an implementation of this interface that permits credentials to be sent only for requests that target specific hosts.
Public Class SelectedHostsCredentialPolicy Implements ICredentialPolicy Public Sub New() End Sub Public Overridable Function ShouldSendCredential(ByVal challengeUri As Uri, ByVal request As WebRequest, ByVal credential As NetworkCredential, ByVal authModule As IAuthenticationModule) As Boolean Implements ICredentialPolicy.ShouldSendCredential Console.WriteLine("Checking custom credential policy.") If request.RequestUri.Host = "www.contoso.com" OrElse challengeUri.IsLoopback = True Then Return True End If Return False End Function End Class
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.