.net core3.1发布时使用https的方式的记录

背景:

  使用了identity server4来做认证中心,但是在子站点加入的时候,遇到下面的错误:

  unknown location   Correlation failed

  根据这篇文章的介绍,把客户端改为https就可以解决  https://www.cnblogs.com/stulzq/p/13954245.html,尝试了一下确实可行,但还有问题,我想用iframe的方式从identityServer4引用子站点的页面,如果一个是http另一个是https,那么就出问题,不能在iframe里显示,所以解决办法就是,把identity server4也换成https。

步骤:

参照下面的文章:

https://www.cnblogs.com/datacool/p/12598307.html

https://www.cnblogs.com/linezero/p/aspnetcorehttps.html

1、添加nuget引用

Install-Package Microsoft.AspNetCore.Server.Kestrel.Https

2、修改CreateWebHostBuilder方法:

public class Program
    {
        public static void Main(string[] args)
        {
var host = CreateWebHostBuilder(args).Build();var config = host.Services.GetRequiredService<IConfiguration>();
            var connectionString = config.GetConnectionString("DefaultConnection");
            host.Run();
        }

        public static IWebHostBuilder CreateWebHostBuilder(string[] args)
        {
            var builder = WebHost.CreateDefaultBuilder(args)
                  .UseStartup<Startup>()
                  .UseSerilog((context, configuration) =>
                  {
                      configuration
                          .MinimumLevel.Debug()
                          .MinimumLevel.Override("Microsoft", LogEventLevel.Warning)
                          .MinimumLevel.Override("System", LogEventLevel.Warning)
                          .MinimumLevel.Override("Microsoft.AspNetCore.Authentication", LogEventLevel.Information)
                          .Enrich.FromLogContext()
                          .WriteTo.File(@"identityserver4_log.txt")
                          .WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message:lj}{NewLine}{Exception}{NewLine}", theme: AnsiConsoleTheme.Literate);
                  });

            builder.ConfigureAppConfiguration((hostingContext, config) =>
            {
                string EnvironmentName = SysCore.ConfigHelper.GetSectionValue("SystemInfo:EnvironmentName");
                if (EnvironmentName != "Development")
                {
                    int intSslPort = Convert.ToInt32(SysCore.ConfigHelper.GetSectionValue("SystemInfo:SslPort"));
                    builder = builder.UseKestrel(options =>
                    {
                        options.Listen(IPAddress.Loopback, intSslPort, listenOptions =>
                        {
                            listenOptions.UseHttps(AppDomain.CurrentDomain.BaseDirectory + "ID4.pfx", "123");
                        });
                    });
                }
            });
            return builder;
        }
    }

3、添加appsetting节点

  "SystemInfo": {
    "EnvironmentName": "Development",
    "SslPort": 5005
  }

4、发布后运行

dotnet AuthorizationCenter.dll

  

原文地址:https://www.cnblogs.com/wjx-blog/p/14798509.html