An ASP.NET project with NuGet Server which requires a client certificate. Created for PowerShell/PowerShell#18209
- ASP.NET 4.8
- NuGet Server 3.4.2
- applicationhost.config
- sslFlags:
Ssl, SslNegotiateCert, SslRequireCert
- iisClientCertificateMappingAuthentication:
true
- sslFlags:
You will need a certificate signed by a trusted CA, as IIS will only accept certs that it trusts.
- Import your trusted client certificate into PowerShell:
$GoodCert = Get-ChildItem -Path "Cert:\LocalMachine\My" -Recurse | Where-Object { $_.Thumbprint -eq "123ABC..." }
- Generate a bad cert:
$BadCert = New-SelfSignedCertificate -DnsName "www.fabrikam.com", "www.contoso.com" -CertStoreLocation "cert:\LocalMachine\My"
- Remember to delete this once finished testing!
- Run the project in debug and copy the URL from the browser
Invoke-WebRequest -Uri "https://localhost:12345/"
should failInvoke-WebRequest -Uri "https://localhost:12345/" -Certificate $GoodCert
should succeedInvoke-WebRequest -Uri "https://localhost:12345/" -Certificate $BadCert
should fail