IntranetZoneCredentialPolicy.ShouldSendCredential メソッド

定義

クライアントの資格情報が、Boolean を使用して行われたリソース要求と共に送信されたかどうかを示す 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

パラメーター

challengeUri
Uri

要求を受信する Uri

request
WebRequest

要求されるリソースを表す WebRequest

credential
NetworkCredential

このメソッドが true を返した場合に要求と共に送信される NetworkCredential

authModule
IAuthenticationModule

認証が必要な場合に認証を実行する IAuthenticationModule

戻り値

要求されたリソースが、要求を行っているクライアントと同じドメインに存在する場合は true。それ以外の場合は false

実装

次のコード例では、 から IntranetZoneCredentialPolicy 派生して、基本認証で Secure Hypertext Transfer Protocol (HTTPS) を使用する要求に対して資格情報を送信できるようにする方法を示します。 HTTPS と基本認証を使用すると、ネットワーク経由で送信される前にユーザー パスワードが暗号化されます。

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

注釈

アプリケーションはこのメソッドを直接呼び出しません。サーバーで認証を IAuthenticationModule 実行するを担当する によって呼び出されます。 このメソッドが を返す false場合、 IAuthenticationModule はサーバーに対してクライアントを認証しません。

このメソッドは、資格情報を指定する要求、または資格情報を指定する オブジェクトを WebProxy 使用する要求に対してのみ呼び出されます。

適用対象