http listener with https support coded in c#

前端 未结 1 1827
一整个雨季
一整个雨季 2021-01-26 07:46

I found a lot of answers how to set httplistener up to use HTTPS, but each one solution requires the use of command line. I guess that is the fastest way to do it but I would li

相关标签:
1条回答
  • 2021-01-26 08:23

    You can load a certificate with:

    X509Certificate cert = new X509Certificate2("MyCert.pfx");
    

    And then install it:

    X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
    store.Open(OpenFlags.ReadWrite);
    if (!store.Certificates.Contains(cert))
    {
        store.Add(cert);
    }
    store.Close();
    

    Of course you might have to change the store name or location for your particular app.

    For running the netsh command, you could look into creating and running a process (i.e. Process.Start) and run netsh.exe. Otherwise you have to mess with the Win32 HttpSetServiceConfiguration function, or the .NET equivalent if there is one.

    You might find this codebox article useful: http://dotnetcodebox.blogspot.com/2012/01/how-to-work-with-ssl-certificate.html

    0 讨论(0)
提交回复
热议问题