Skip to content

Instantly share code, notes, and snippets.

@mika76
Last active March 19, 2019 09:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mika76/e5058a84de1e53010bbe5f0cac1ceffa to your computer and use it in GitHub Desktop.
Save mika76/e5058a84de1e53010bbe5f0cac1ceffa to your computer and use it in GitHub Desktop.
Create self signed cert and hosting for self hosted owin webapi

Create self-signed cert

New-SelfSignedCertificate -Subject "SomeWebApi"

Get cert thumbprint

Get-ChildItem -path cert:\LocalMachine\My

Add the ssl binding (I'm pretty sure the ApplicationID is a random GUID - you can generate one at https://www.guidgenerator.com/)

Add-NetIPHttpsCertBinding 
	-IpPort "0.0.0.0:8181"  
	-ApplicationId "{12345678-db90-4b66-8b01-88f7af2e36bf}" 
	-CertificateHash "3876BF4236E1A7B2C3A29FB1793924575609FA59" 
	-CertificateStoreName "My" 
	-NullEncryption $false

Register the acl

$port=8181
$domainUser="Everyone"
& netsh http add urlacl url=https://+:$port/ user=$domainUser

If you still get errors after this make sure there are no duplicate acl bindings

& netsh http show urlacl

which can be removed using

& netsh http delete urlacl url=https://+8181/

NOTE: In the Owin WebApi make sure the WebAp is listening on same url (notice the https and +) https://+:8181/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment