【发布时间】:2023-03-03 12:43:01
【问题描述】:
我正在使用 ASP.NET core 2.0.0 并使用它创建了要在 HTTPS 中运行的 Web 应用程序。要在 HTTPS 中运行,我在 Program.cs 中使用了以下代码
string directory = Directory.GetCurrentDirectory();
string portNumber = Helper.getPortNumber(directory);
var cert = new X509Certificate2("file1.pfx", "ccc");
var host = new WebHostBuilder()
.UseKestrel(cfg => cfg.UseHttps(cert))
.UseUrls("https://localhost:53135")
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
然后将 APPURL 更改为https://localhost:53135/。如果我运行程序,我会收到如下错误:
"An error occurred attempting to determine the process id of service.exe which is hosting your application.One or more errors occurred."
但是如果我给端口号 44300 到 44399 没有例外,并且链接成功托管。我已经阅读了一个使用 SSL 运行 IIS Express 的链接,端口号应该在 44300 到 44399 的范围内。我需要在所有端口中运行我的应用程序。谁能指导我如何做到这一点?
【问题讨论】:
-
这个博客有一个解决方法,可以使用任何带有 SSL 的端口:hanselman.com/blog/…
-
感谢您的回复。我无法理解该博客中提到的内容,因为我对所有这些概念都很陌生。那么您能否具体说明解决方法是在哪一部分提到的?
-
这是针对 IISExpress 的限制。如果您想要更多控制,请使用 IIS,在其中放置自签名(甚至是 Visual Studio)证书,指定您想要的任何端口。直接构建/发布到 IIS。