Enabling SSL for Self Hosted Nancy
One of the things I like about Nancy is the ease of creating self hosted HTTP services.
Here’s how to enable HTTPS for your service.
First of all, create your SSL certificate:
$ openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem $ openssl pkcs12 -export -in cert.pem -inkey key.pem -out mycert.pfx
Then go to ‘Manage Computer Certificates’ in the start menu (I’m using Windows 8.1).
Right click on ‘Personal’ and import the freshly created mycert.pfx
.
Now go to your newly installed certificate, and get the thumbprint:
Now you need to register the URL with Windows:
$ netsh http add urlacl url=https://+:4443/ user=YOUR_USERNAME $ netsh http add sslcert ipport=0.0.0.0:4443 certhash=YOUR_THUMBPRINT_WITHOUT_SPACES appid={06aabebd-3a91-4b80-8a15-adfd3c8a0b14}
You need to substitute your username, and the certificate thumbprint you copied (without the spaces)
The appid is just a random guid, feel free to create your own.
Now start nancy on this Uri https://localhost:4443/
.
using (var host = new NancyHost(new Uri("https://localhost:4443/"))) { host.Start(); Console.ReadKey(); }
mbharallmansitech 1:38 pm on December 16, 2014 Permalink | Log in to Reply
How to check that HTTPS request working in Nancy Host or not?
Richard 1:50 pm on December 16, 2014 Permalink | Log in to Reply
send it an HTTPS request from your browser?
mbharallmansitech 2:07 pm on December 16, 2014 Permalink | Log in to Reply
I send request from browser. but i got no response.
Richard 2:12 pm on December 16, 2014 Permalink | Log in to Reply
Sounds like it didn’t work.
Try putting some logging in your app, and looking at the HTTP traffic in fiddler.
Manuraj 2:20 pm on December 16, 2014 Permalink | Log in to Reply
Let me try once again..
Manuraj 2:47 pm on December 16, 2014 Permalink | Log in to Reply
I created new certificate and then i register them successfully. Then I use browser to send https request and apply break point. But it was not working.
Manuraj 5:53 am on December 17, 2014 Permalink | Log in to Reply
Getting error NET::ERR_CERT_AUTHORITY_INVALID
Manuraj 6:47 am on December 18, 2014 Permalink | Log in to Reply
Getting error HTTP Error 503. The service is unavailable on browser. Can you guide me how i can get response using HTTPS.
Manuraj 2:14 pm on January 5, 2015 Permalink | Log in to Reply
Hi Richard,
I am able to create certificate and able to register it successfully.
But when i restart computer, Then nancy started but url related to nancy not work.
It give error
“GET https://localhost:4444/t1 net::ERR_CONNECTION_RESET”.
I try to find the solution. But got no solution.
Manuraj 2:58 pm on January 5, 2015 Permalink | Log in to Reply
Every time i have to run
netsh http add sslcert ipport=0.0.0.0:4443 certhash=YOUR_THUMBPRINT_WITHOUT_SPACES appid={06aabebd-3a91-4b80-8a15-adfd3c8a0b14}
After that it work. But after restart again i have to use same command.
Is there any solution for this.
afterhourscoding 2:28 pm on June 8, 2015 Permalink | Log in to Reply
The following command failed for me:
netsh http add sslcert ipport=0.0.0.0:4443 certhash=YOUR_THUMBPRINT_WITHOUT_SPACES appid={06aabebd-3a91-4b80-8a15-adfd3c8a0b14}
With error:
SSL Certificate add failed, Error 1312
A specified logon session does not exist. It may already have been terminated.
I had to import the certificate using MMC.exe’s certificate for local computer module instead of using certmgr.msc. You can watch the certificate listed using ‘certutil -store My’
channygold 10:42 am on July 30, 2015 Permalink | Log in to Reply
Thanks for this post. Really helpful!
Divyanshu Vyas 10:07 am on May 8, 2019 Permalink | Log in to Reply
This will work if you register your URL as below :
netsh http add urlacl url=https://YOURIPADDRESS:4443/ user=YOUR_USERNAME
instead of
netsh http add urlacl url=https://+:4443/ user=YOUR_USERNAME