dotnet / WatsonWebserver

Watson is the fastest, easiest way to build scalable RESTful web servers and services in C#.
MIT License
411 stars 84 forks source link

Watson.Lite - SSL from PFX Example? #145

Closed winkmichael closed 5 months ago

winkmichael commented 5 months ago

Hello Joel,

Thanks for your reply the other day about Framework, everything is just fine with framework.

I'm trying to implement SSL using Watson.Lite loading a PFX, but I can't figure out how to pass either Ssl.Enable or any Settings.SSL and ultimately start the server with the certificate. I keep coming up with code that looks like this but this doesn't work.

Any help or a quick example you can point me at ,would be very much appreciated.

static void Main() { _Settings = new WebserverSettings { Hostname = _Hostname, Port = _Port, Ssl.Enable = true;

};

  X509Certificate2 certificate = LoadCertificateFromPfx("certificate.pfx", "password");
 _Server = new WatsonWebserver.Lite.WebserverLite(_Settings, DefaultRoute, certificate);
winkmichael commented 5 months ago

I haven't tested, as I am missing the pfx file but I believe this is the way for anyone googling.

 static void Main()
 {
     _Settings = new WebserverSettings
     {
         Hostname = _Hostname,
         Port = _Port,
         Ssl = new WebserverSettings.SslSettings
         {
             Enable = true,
             AcceptInvalidAcertificates = true,
             PfxCertificateFile = "file.pfx",
             PfxCertificatePassword ="password"
         }
     };
     _Server = new WatsonWebserver.Lite.WebserverLite(_Settings, DefaultRoute);
     _Server.Start();