Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

ASP .NET Core - Windows Service - Make it secure using https

$
0
0

Hello:

I have ASP .NET Core web API running as a windows service on a port, 60001.

public static void Main(string[] args)
        {
            bool isService = true;
            if (Debugger.IsAttached || args.Contains("--console"))
            {
                isService = false;
            }

            var pathToContentRoot = Directory.GetCurrentDirectory();
            if (isService)
            {
                var pathToExe = Process.GetCurrentProcess().MainModule.FileName;
                pathToContentRoot = Path.GetDirectoryName(pathToExe);
            }


            var config = new ConfigurationBuilder()
                //.SetBasePath(Directory.GetCurrentDirectory())
                .SetBasePath(pathToContentRoot)
                //Specifying the IP or host ASP.NET Core listens on
                .AddJsonFile("hosting.json", optional: false, reloadOnChange: true)
                .Build();



            var host = new WebHostBuilder()
                .UseKestrel()
                .UseContentRoot(pathToContentRoot)
                .UseConfiguration(config)
                .UseIISIntegration()
                .UseStartup<Startup>()
                .UseApplicationInsights()
                .Build();


            if (isService)
            {
                host.RunAsService();
            }
            else
            {
                host.Run();
            }
        }

After the Windows Service is started, I'm able to access it using http://machinename:60001/api

Now, the requirement is to make it secure with https. I do have purchased a SSL certificate available (NOT self signed) and I'm wondering how would I apply the certificate since I'm running it as a Windows Service. 

Any help will be appreciated.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>