zoukankan      html  css  js  c++  java
  • .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

      

  • 相关阅读:
    log4j 日志配置
    找出两个列表元素中相同的元素
    列表元素去重
    hdu 2149 Public Sale(巴什博弈变形)
    POJ 3169 Layout (差分约束+SPFA)
    hdu 1494 跑跑卡丁车(动态规划)
    hdu 3177 Crixalis's Equipment(贪心)
    HDU 1576 A/B(扩展欧几里德变形)
    POJ 1061青蛙的约会(扩展欧几里德)
    IE6下的CSS多类选择符
  • 原文地址:https://www.cnblogs.com/wjx-blog/p/14798509.html
Copyright © 2011-2022 走看看