简体   繁体   中英

Refused to connect to localhost when running web application as windows service

I am trying to run a web application as a windows service. I managed to get the service to start by adding builder.Host.UseWindowsService(); to my Program.cs and I also set builder.WebHost.UseUrls(settings.BaseUrl); . The baseUrl is set to "BaseUrl": "https://localhost:5011;http://*:5011" in the settings.json file.

I published the application using dotnet publish -c Release --self-contained --runtime win-x64 -p:PublishSingleFile=true . When I run the .exe file then the application starts up and I am able to navigate to https://localhost:5011 successfully. But the site does not load when I try running the application as a windows service.

This is my installer.bat for starting the windows service:

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

The service starts up but when I navigate to https://localhost:5011 then I am greeted with a "This site can't be reached. localhost refused to connect." screen.

I feel like I am missing something small that's causing this to happen. I can't seem to find any solutions online.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM