Language

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

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

authModule
IAuthenticationModule

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

返品

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

実装

例

次のコード例は、基本認証でセキュリティで保護されたハイパーテキスト転送プロトコル (HTTPS) を使用する要求に対して資格情報を送信できるように、 IntranetZoneCredentialPolicy から派生する方法を示しています。 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 )
      {
         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;
        }
    }

注釈

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

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

適用対象