Double-click the SSL Settings feature in the middle pane.
Under Client Certificates, select one of these options:
Accept: IIS will accept a certificate from the client, but does not require one.
Require: Require a client certificate. (To enable this option, you must also select "Require SSL")
你也可以设置这些选项ApplicationHost.config文件:
xml
<system.webServer> <security>
<access sslFlags="Ssl, SslNegotiateCert" />
<!-- To require a client cert: -->
<!-- <access sslFlags="Ssl, SslRequireCert" /> -->
</security>
</system.webServer>
The SslNegotiateCert flag means IIS will accept a certificate from the client, but does not require one (equivalent to the "Accept" option in IIS Manager). To require a certificate, set the SslRequireCert flag. For testing, you can also set these options in IIS Express, in the local applicationhost.Config file, located in "Documents\IISExpress\config".
为了测试创建一个客户端证书
For testing purposes, you can use MakeCert.exe to create a client certificate. First, create a test root authority:
Makecert will prompt you to enter a password for the private key.
Next, add the certificate to the test server's "Trusted Root Certification Authorities" store, as follows:
Open MMC.
Under File, select Add/Remove Snap-In.
Select Computer Account.
Select Local computer and complete the wizard.
Under the navigation pane, expand the "Trusted Root Certification Authorities" node.
On the Action menu, point to All Tasks, and then click Import to start the Certificate Import Wizard.
Browse to the certificate file, TempCA.cer.
Click Open, then click Next and complete the wizard. (You will be prompted to re-enter the password.)
Now create a client certificate that is signed by the first certificate:
console
makecert.exe -pe -ss My -sr CurrentUser -a sha1 -sky exchange -n "CN=name" -eku 1.3.6.1.5.5.7.3.2 -sk SignedByCA -ic TempCA.cer -iv TempCA.pvk
在Web API中使用客户端证书
On the server side, you can get the client certificate by calling GetClientCertificate on the request message. The method returns null if there is no client certificate. Otherwise, it returns an X509Certificate2 instance. Use this object to get information from the certificate, such as the issuer and subject. Then you can use this information for authentication and/or authorization.