簡體   English   中英

如何在端口號 53135 中使用 IIS Express 運行 HTTPS

[英]How to run HTTPS with IIS Express in port number 53135

我正在使用 ASP.NET core 2.0.0,並使用它創建了 Web 應用程序以在 HTTPS 中運行。要在 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,則不會出現異常並且鏈接成功托管。應用程序在所有端口。誰能指導我如何做到這一點?

為此,您需要管理員權限。

打開具有管理員權限的命令提示符,然后執行:

netsh http show sslcert

搜索IP:Port介於44300到44399之間的塊,並復制證書哈希和應用程序ID值。 然后執行:

netsh http add sslcert ipport=0.0.0.0:53135 certhash=<HASH> appid="<APPLICATION_ID>"

用第一步中復制的哈希值替換這些值。

之后,編輯.csproj以及可能的.csproj.user文件,以確保Visual Studio將使用正確的端口啟動應用程序,例如:

<IISExpressSSLPort>53135</IISExpressSSLPort>

有時,您可能還需要編輯.vs \\ config \\ applicationhost.config文件,查找綁定並更改其端口。 將其更改為:

<binding protocol="https" bindingInformation="*:53135:localhost" />

確保編輯正確項目的綁定。

對我來說,它的工作原理是將端口更改為 44300。

根據這篇文章httpsIISExpress端口應該類似於4443xx

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM