Iis 将ASP.NET核心模块配置为以https而不是http作为IdentityServer 4的主机
我遇到的问题是,当我尝试在使用SSL的IIS服务器上托管IdentityServer4的实现时。(完全SSL严格) 当单独在Kestrel上运行我的应用程序并激活SSL时,它工作正常,IdentityServer的Iis 将ASP.NET核心模块配置为以https而不是http作为IdentityServer 4的主机,iis,asp.net-core,identityserver4,Iis,Asp.net Core,Identityserver4,我遇到的问题是,当我尝试在使用SSL的IIS服务器上托管IdentityServer4的实现时。(完全SSL严格) 当单独在Kestrel上运行我的应用程序并激活SSL时,它工作正常,IdentityServer的IssuerUri和Discovery Endpoints使用SSL绑定。但是,当我将其托管在ASP.NET核心模块后面时,它将其托管在http://localhost:{random port},依次为非https的Identityserver生成IssuerUri和端点 我尝试了以
IssuerUri
和Discovery Endpoints
使用SSL绑定。但是,当我将其托管在ASP.NET核心模块后面时,它将其托管在http://localhost:{random port}
,依次为非https的Identityserver生成IssuerUri
和端点
我尝试了以下方法,但没有成功:
请确保我在IIS网站上拥有用于
https绑定和端口80上的已删除绑定
已尝试更改web.config中的环境变量ASPNETCORE\u URL
指向https地址
已尝试在web.config中重写和重定向规则
查找IISOptions
上的设置(由使用。使用iIsIntegration()
)
在我的启动类中绑定到特定url或更改协议
试图找到类似的设置,如RequireSSL
(IdentityServer 3)或
在IdentityServer4中需要TTPSMetadata
更改了startup类中IdentityServer选项中的IssuerUri
希望它也能更新其他端点
我可能错过了一些非常明显的东西,但现在我不知道那可能是什么
非常感谢社区的任何帮助:-)
Program.cs代码
publicstaticvoidmain(字符串[]args)
{
Console.Title=“IdentityServer”;
var config=new ConfigurationBuilder()
.SetBasePath(目录.GetCurrentDirectory())
.AddJsonFile(“kestrelHosting.json”,可选:true)
.AddCommandLine(args)
.Build();
var host=new WebHostBuilder()
.UseConfiguration(配置)
.UseKestrel(选项=>
{
//options.ThreadCount=4;
options.NoDelay=true;
使用https(“VismaCert.pfx”、“Visma123”);
//options.UseConnectionLogging();
})
.UseContentRoot(目录.GetCurrentDirectory())
.Useii整合()
.UseStartup()
.Build();
host.Run();
}
AspNetCoreModule是一个SSL终端,它不会通过HTTPS与Kestrel通信。它所做的是通过一个头转发原始方案,以便您可以在生成URL/链接时使用它。默认情况下,UseIISIntegration包含一个ForwardedHeaders中间件,它将获取这些头并将其应用于请求字段。但是,在某些情况下,默认设置无法处理标题。这里有很多参考资料:谢谢@Tratcher的回复。在遵循您的链接并在ARR中添加响应头之后,我现在得到以下内容。“X-FORWARDED-HOST:xxxxxxxx.xxx.xxx”、“X-FORWARDED-SCHEMA:https”、“X-FORWARDED-PROTO:https,http”和“X-FORWARDED-For:xx.xx.X.xx:xxxxxx”。不幸的是,identityserver似乎没有注意到这些更改,而是读取HttpContext.Request.Schema,而不是检查是否为其BaseUrlMiddleware设置了值为https的Request.Header[“X-Forwarded-Proto”],因此,我将向他们提出一个关于如何最好地继续的新问题。在转发头上,选项禁用要求头对称。您的proto和For有不同数量的值。您好,是的,我想知道如果两者都存在,中间件如何能够选择使用哪个协议。现在,我已经在代码中设置了这个值,但我仍然得到了双值,并且没有使用https<代码>app.UseForwardedHeaders(新ForwardedHeaders选项{ForwardedHeaders=ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto,ForwardLimit=null,RequiredHeaderSymmetry=false})代码>如果设置正确,HttpContext.Request.Schema是否会将其值设置为https而不是http?是的,如果设置正确,则Request.Scheme将为https。Try ForwardLimit=2我按照您的建议尝试设置ForwardLimit=2
,但它仍然只将Request.Schema设置为http。我仍然在X-Forwarded-Proto
头中设置了“https”和“http”两个值。我能让它工作的唯一方法是在codecontext.Request.Scheme=“https”中手动设置它代码>。如果我应该将其设置为https或不设置为https,则通过应用程序设置进行管理,但我认为在转发的协议头上获取它的方法是一种更好的方法,如果我能够让它工作的话。
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();
}