IIS: Add a certificate (name as "localhost-cert") :
cmd>makecert -sr LocalMachine -ss My -n CN=localhost -sky exchange
This command creates a certificate with the subject “localhost” and places it in the Personal store of the local computer.The subject name for a service certificate should match the name of host computer in the URL that the client application uses to connect to the service
After Add the certificate, certificate will appear at IIS Server Certificates and Personal store of the local computer
How to open LocalMachine Certificates Management Console
Once this command has been run and succeeded, you need to make this certificate a trusted authority. You do this by using the MMC snap in console. Go to the run window and type "mmc", hit enter. Then in the window that opens (called the "Microsoft Management Console, for those who care) perform the following actions.
File -> Add/Remove Snap-in -> Add… -> Double click Certificates -> Select Computer Account and Click Next -> Finish -> Close -> OK
Then select the Certificates (Local Computer) -> Personal -> Certificates node.
http://msdn.microsoft.com/en-us/library/ms733791.aspx
Bind sthe certificate with the thumbprint to the port
cmd>netsh http add sslcert ipport=0.0.0.0:1234 certhash=22e12b61467135349fa061446a89c30369e95fcb appid={00112233-4455-6677-8899-AABBCCDDEEFF}
- The certhash parameter specifies the thumbprint of the certificate.
- The ipport parameter specifies the IP address and port, and functions just like the -i switch of the Httpcfg.exe tool described.
- The appid parameter is a GUID that can be used to identify the owning application.
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(
delegate
{
return true;
});
ServicePointManager.ServerCertificateValidationCallback += customXertificateValidation;
private static bool customXertificateValidation(object sender, X509Certificate cert,
X509Chain chain, SslPolicyErrors error)
{
X509Certificate2 certificate = (X509Certificate2)cert;
if (certificate.Subject == "CN=127.0.0.1" && !String.IsNullOrEmpty(certificate.Thumbprint) &&
certificate.Thumbprint.ToLower() == "cfdf5d1140b94614d047dd77c7bd4d4d4422e1c9")
{
return true;
}
return false;
}