2

I need to start a web server self-contained on a specific port with HTTPS from a C# Desktop Windows application, without using IIS.

Looking to see if there is a way to do this does not require installing the HTTPS certificate into windows with netsh. Just a simple lightweight server that can load up a certificate and/or create one at runtime. I just need to be able to read the URL requests and return the content programmatically based on that.

Built-in .NET and third party suggestions are welcome! I haven't been able to find anything.

Bonus points if no administrator permissions are needed as well (avoiding using netsh to add the port namespace, which is required with most of the built in .NET http libs)

Thank you!

2 Answers 2

3

Try using .Net Core with Kestral webserver.

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/servers/kestrel?view=aspnetcore-2.1

SSL Options

options.Configure(context.Configuration.GetSection("Kestrel"))
    .Endpoint("HTTPS", opt =>
    {
        opt.HttpsOptions.SslProtocols = SslProtocols.Tls12;
    });

SSL Certificate

.UseKestrel(options =>
        {
            options.Listen(IPAddress.Loopback, 8000);
            options.Listen(IPAddress.Loopback, 8001, listenOptions =>
            {
                listenOptions.UseHttps("testCert.pfx", "testPassword");
            });
        });

Kestral is a base component from Microsoft specifically with .Net Core in mind.

0
3

As well as the Kestral solution Todd provided (thanks!), I discovered a third party library called Ceen.Httpd - this is a very lightweight HTTPd server that I was able to just drop into my project that supports SSL.

https://github.com/kenkendk/ceenhttpd

Using SSL was quite straight-forward, here is the sample code they provide, adapted to use SSL.

        var tcs = new CancellationTokenSource();
        var config = new ServerConfig()
            .AddLogger(new CLFStdOut())
            .AddRoute(new FileHandler(args.Length == 0 ? "." : args[0]));                

        var usessl = true;
        config.SSLCertificate = new X509Certificate2("idsrv3test.pfx", "idsrv3test");

        var task = HttpServer.ListenAsync(
            new IPEndPoint(IPAddress.Any, 9000),
            usessl,
            config,
            tcs.Token
        );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.