簡體   English   中英

以 windows 服務運行 web 應用程序時拒絕連接到 localhost

[英]Refused to connect to localhost when running web application as windows service

我正在嘗試將 web 應用程序作為 windows 服務運行。 我設法通過添加builder.Host.UseWindowsService(); 到我的Program.cs ,我還設置了builder.WebHost.UseUrls(settings.BaseUrl); . baseUrl 在 settings.json 文件中設置為"BaseUrl": "https://localhost:5011;http://*:5011"

我使用dotnet publish -c Release --self-contained --runtime win-x64 -p:PublishSingleFile=true發布了應用程序。 當我運行.exe文件時,應用程序啟動,我能夠成功導航到https://localhost:5011 但是當我嘗試將應用程序作為 windows 服務運行時,該站點不會加載。

這是我的 installer.bat 用於啟動 windows 服務:

sc create TestService binPath= %~dp0MyProgram.exe
sc failure TestService actions= restart/60000/restart/60000/""/60000 reset= 86400
sc start TestService 
sc config TestService start=auto

服務啟動,但是當我導航到https://localhost:5011時,我收到“無法訪問此站點。localhost 拒絕連接”。 屏幕。

我覺得我錯過了導致這種情況發生的一些小事情。 我似乎無法在網上找到任何解決方案。

暫無
暫無

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

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