ASP.NET Core Web应用程序使用HTTPS/SSL

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yhld456/article/details/88999687
  1. 创建一个ASP.NET Core Web应用程序
  2. 将证书文件localhost.p12复制到项目的根目录(证书创建参考我的博客《代替OCX Activex等IE浏览器插件的一种方式 》)
  3. 创建配置文件config.json(新建文件在项目根路径)
  4. 编写配置文件的内容
{
  "Kestrel": {
    "EndPoints": {
      "HttpsInlineCertFile": {
        "Url": "https://localhost:5006",
        "Certificate": {
          "Path": "localhost.p12",
          "Password": "123456"
        }
      }
    }
  }
}
  1. 修改Program.cs中的Main方法内容如下
 var config = new ConfigurationBuilder()
           .SetBasePath(Directory.GetCurrentDirectory())
           .AddJsonFile("config.json", optional: true)
           .Build();

            var host = WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .UseConfiguration(config)
                .Build();

            host.Run();

猜你喜欢

转载自blog.csdn.net/yhld456/article/details/88999687