此问题通常是由于ASP.NET Core Webapi的SSL配置错误导致的。解决此问题的方法是在应用程序的启动配置中添加正确的证书和端口配置。以下是一些示例代码来解决此问题:
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup()
.UseKestrel(options =>
{
options.ListenAnyIP(5001, listenOptions =>
{
listenOptions.UseHttps("certificate.pfx", "password");
});
});
在这个例子中,我们可以看到'UseKestrel”函数的使用。这个函数允许我们配置Kestrel启动的应用程序。可以使用'options.ListenAnyIP”来指定要侦听的端口,而'listenOptions.UseHttps”则说明要使用的证书和密码。
此外,您还需要在应用程序的配置文件中添加以下行来指定要使用的证书文件和密码:
"Kestrel": {
"EndPoints": {
"Https": {
"Url": "https://localhost:5001",
"Certificate": {
"Path": "certificate.pfx",
"Password": "password"
}
}
}
}
使用这些配置,应用程序将能够正确配置SSL,并可以避免'Failed to determine the https port for redirect”错误。
上一篇:ASP.NETCore5数据注释错误消息中标题的本地化
下一篇:ASP.NETCore5WebAPI和EntityFramework在IDE中运行正常,但发布到文件夹并安装在IIS中时无法工作。