Condividi tramite


Metodo IHttpRequest::NegotiateClientCertificate

Avvia la negoziazione del certificato client con un client Web.

Sintassi

HRESULT NegotiateClientCertificate(  
   IN BOOL fAsync,  
   OUT BOOL* pfCompletionPending = NULL  
)   

Parametri

fAsync
[IN] true per specificare che la negoziazione deve avvenire in modo asincrono; in caso contrario, false.

pfCompletionPending
[OUT] true per specificare che un completamento asincrono è in sospeso; in caso contrario, false.

Valore restituito

Oggetto HRESULT. I valori possibili includono, ma non sono limitati a, quelli indicati nella tabella seguente.

valore Definizione
S_OK Indica che l'operazione è riuscita.
E_FAIL Indica che l'operazione non è riuscita.

Commenti

Gli sviluppatori possono usare il metodo per avviare manualmente la NegotiateClientCertificate negoziazione del certificato client con un client Web, anche se IIS è configurato per accettare o ignorare i certificati client. NegotiateClientCertificate supporta sia l'operazione sincrona che asincrona specificando l'impostazione appropriata nel fAsync parametro . Quando il modulo chiama NegotiateClientCertificate in modo asincrono, il modulo deve restituire l'elaborazione alla pipeline integrata di elaborazione delle richieste immediatamente dopo aver chiamato il metodo se il valore indica che un pfCompletionPending completamento asincrono è in sospeso.

Esempio

Nell'esempio seguente viene illustrato come chiamare NegotiateClientCertificate il metodo .

REQUEST_NOTIFICATION_STATUS
CMyHttpModule::OnBeginRequest(
                              IHttpContext*       pHttpContext,
                              IHttpEventProvider* // pProvider  
                              )
{
   static long cnt;     
   InterlockedIncrement (&cnt);  // keep track of how many times we are called
   HRESULT hr = E_FAIL;
   IHttpRequest *pIHTTPR = pHttpContext->GetRequest();

   HTTP_REQUEST * pRawRequest = pIHTTPR->GetRawHttpRequest();
   HTTP_COOKED_URL hcu = pRawRequest->CookedUrl;

   // Send URL and count to the trace window
   TRC_MSGW_FULL( L"cnt = " << cnt << " URI: " << hcu.pFullUrl );

   // return immediately if not a HTTPS request
   if ( pRawRequest->pSslInfo == NULL ){
      TRC_MSG( "connection is not using SSL");
      return RQ_NOTIFICATION_CONTINUE;
   }

   // change the bForce flag to test behavior of forcing load of client cert
   bool bForce=true;
   if(bForce){
      TRC_MSG("forcing load of client cert");
      hr = pIHTTPR->NegotiateClientCertificate(FALSE);
      if(FAILED(hr)){
         LOG_ERR_HR(hr, "NegotiateClientCertificate : HR = ");
         return RQ_NOTIFICATION_CONTINUE;
      }
   }
   else
      TRC_MSG("Not forcing load of client cert");

   HTTP_SSL_CLIENT_CERT_INFO *pClientCertInfo;
   BOOL fccNeg;
   hr = pIHTTPR->GetClientCertificate(&pClientCertInfo,&fccNeg);

   // If you have not selected "Require Client Certificates" or called
   // NegotiateClientCertificate(), you  may get  ERROR_NOT_FOUND 

   if( hr == HRESULT_FROM_WIN32(ERROR_NOT_FOUND)){
      TRC_MSG( "Cert not found" );
      return RQ_NOTIFICATION_CONTINUE;
   }
   if(FAILED(hr)){
      LOG_ERR_HR("GetClientCertificate", hr);
      return RQ_NOTIFICATION_CONTINUE;
   }	

   if( fccNeg && pClientCertInfo != NULL){
      ULONG uSiz = pClientCertInfo->CertEncodedSize;
      TRC_MSG( "cert size: " << uSiz  \
         << " Previously negotiated " << fccNeg );
      unsigned long certCrc = genCRC(pClientCertInfo->pCertEncoded,
         pClientCertInfo->CertEncodedSize);
      TRC_MSG( "cert crc: " << certCrc );
   }
   else
      TRC_MSG( "No client certificate.");

   return RQ_NOTIFICATION_CONTINUE;
}

Per altre informazioni su come creare e distribuire un modulo DLL nativo, vedere Procedura dettagliata: Creazione di un modulo HTTP Request-Level tramite codice nativo.

Facoltativamente, è possibile compilare il codice usando la __stdcall (/Gz) convenzione di chiamata anziché dichiarare in modo esplicito la convenzione di chiamata per ogni funzione.

Requisiti

Tipo Descrizione
Client - IIS 7.0 in Windows Vista
- IIS 7.5 in Windows 7
- IIS 8.0 in Windows 8
- IIS 10.0 in Windows 10
Server - IIS 7.0 in Windows Server 2008
- IIS 7.5 in Windows Server 2008 R2
- IIS 8.0 in Windows Server 2012
- IIS 8.5 in Windows Server 2012 R2
- IIS 10.0 in Windows Server 2016
Prodotto - IIS 7.0, IIS 7.5, IIS 8.0, IIS 8.5, IIS 10.0
- IIS Express 7.5, IIS Express 8.0, IIS Express 10.0
Intestazione Httpserv.h

Vedere anche

Interfaccia IHttpRequest
Metodo IHttpRequest::GetClientCertificate