Linux中发布.netcore时启用ssl

 public static IWebHostBuilder CreateWebHostBuilder(string[] args)
        {
           var dic= ReadConfig();
            return WebHost.CreateDefaultBuilder(args)
                 .UseKestrel(option => {
                     option.Listen(System.Net.IPAddress.Any, Convert.ToInt32(dic["server_port"]), (lop) => {
                         lop.UseHttps(dic["pfx_name"], dic["pfx_pswd"]);
                     });
                 })
                //.UseConfiguration(new ConfigurationBuilder().AddJsonFile("config.json", true).Build())
                .UseStartup<Startup1>()
                .ConfigureLogging((hostingContext, logging) =>
                {
                    logging.ClearProviders();
                    logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                    //暂时不根据dev还是product环境来屏蔽日志的console或者文件
                    logging.AddConsole();
                    //logging.AddDebug(); //output窗口
                })
                .UseNLog();
        }

 

 private static Dictionary<string, string> ReadConfig()
        {
            try
            {
                using (FileStream fs = new FileStream("config.json", FileMode.Open))
                {
                    using (StreamReader sr = new StreamReader(fs))
                    {
                        return JsonConvert.DeserializeObject<Dictionary<string, string>>(sr.ReadToEnd());
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }


        }
config.json:

{
"pfx_name": "server_keystore.pfx",
"pfx_pswd": "87654321",
"server_port": 443
}

上一篇:创建项目签名证书


下一篇:0101 lc.2022数组