public static IWebHostBuilder CreateWebHostBuilder(string[] args){var dic= ReadConfig();return WebHost.CreateDefaultBuilder(args).UseKestrel(option = {option.Listen(System.Net.IPAddress.Any, Convert....

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
}
沃梦达教程
本文标题为:Linux中发布.netcore时启用ssl


基础教程推荐
猜你喜欢
- C#通过GET/POST方式发送Http请求 2023-04-28
- c#中利用Tu Share获取股票交易信息 2023-03-03
- C# – NetUseAdd来自Windows Server 2008和IIS7上的NetApi32.dll 2023-09-20
- C#中类与接口的区别讲解 2023-06-04
- 京东联盟C#接口测试示例分享 2022-12-02
- 使用c#从分隔文本文件中插入SQL Server表中的批量数据 2023-11-24
- C# Winform实现石头剪刀布游戏 2023-01-11
- Unity shader实现多光源漫反射以及阴影 2023-03-04
- C#集合查询Linq在项目中使用详解 2023-06-09
- c#读取XML多级子节点 2022-11-05