将ASP.NET核心模块配置为以https而不是http为IdentityServer 4

时间:2017-02-08 21:24:41

标签: iis asp.net-core identityserver4

我遇到的问题是当我尝试在使用SSL的IIS服务器上托管IdentityServer4的实现时。 (完全SSL严格)

当单独使用Kestrel运行我的应用程序并激活SSL时,它运行正常,IdentityServer的IssuerUriDiscovery Endpoints使用SSL绑定。但是,当我将它托管在ASP.NET核心模块后面时,它会在http://localhost:{random port}上托管它,而后者会为不是https的Identityserver生成IssuerUriEndpoints

我尝试了以下但没有成功:

  1. 确保我在IIS网站上有一个有效的证书 https绑定并删除端口80上的绑定

  2. 尝试更改web.config中的环境变量ASPNETCORE_URLS 指向https地址。

  3. 尝试在web.config中重写和重定向规则。

  4. 查看IISOptions上的设置(由.UseIISIntegration()使用) 在我的启动类中绑定到特定的URL或更改协议。

  5. 试图找到类似RequireSSL(IdentityServer 3)或类似的设置 IdentityServer4中的RequireHttpsMetadata

  6. 更改了启动类中IdentityServer选项中的IssuerUri 希望它也可以更新其他端点。

  7. 我可能已经错过了一些非常明显的东西但是现在我对这可能是什么没有任何线索。

    非常感谢社区的任何帮助: - )

      

    Program.cs代码

        public static void Main(string[] args)
        {
            Console.Title = "IdentityServer";
    
            var config = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("kestrelHosting.json", optional: true)
                .AddCommandLine(args)
                .Build();
    
            var host = new WebHostBuilder()
                .UseConfiguration(config)
                .UseKestrel(options =>
                {
                    // options.ThreadCount = 4;
                    options.NoDelay = true;
                    options.UseHttps("VismaCert.pfx", "Visma123");
                    //options.UseConnectionLogging();
                })
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .Build();
    
            host.Run();
        }
    

1 个答案:

答案 0 :(得分:1)

AspNetCoreModule是一个SSL终结器,它不会通过HTTPS与Kestrel通信。它所做的是通过标题转发原始方案,以便在生成URL /链接时使用它。默认情况下,UseIISIntegration包含一个ForwardedHeaders中间件,它将采用这些标头并将它们应用于请求字段。但是,在某些情况下,默认设置无法处理标头。这里有很多引用:https://github.com/aspnet/Docs/issues/2384