[英]Refused to connect to localhost when running web application as windows service
I am trying to run a web application as a windows service.我正在尝试将 web 应用程序作为 windows 服务运行。 I managed to get the service to start by adding
builder.Host.UseWindowsService();
我设法通过添加
builder.Host.UseWindowsService();
to my Program.cs
and I also set builder.WebHost.UseUrls(settings.BaseUrl);
到我的
Program.cs
,我还设置了builder.WebHost.UseUrls(settings.BaseUrl);
. . The baseUrl is set to
"BaseUrl": "https://localhost:5011;http://*:5011"
in the settings.json file. baseUrl 在 settings.json 文件中设置为
"BaseUrl": "https://localhost:5011;http://*:5011"
。
I published the application using dotnet publish -c Release --self-contained --runtime win-x64 -p:PublishSingleFile=true
.我使用
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.当我运行
.exe
文件时,应用程序启动,我能够成功导航到https://localhost:5011
。 But the site does not load when I try running the application as a windows service.但是当我尝试将应用程序作为 windows 服务运行时,该站点不会加载。
This is my installer.bat for starting the windows service:这是我的 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
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."服务启动,但是当我导航到
https://localhost:5011
时,我收到“无法访问此站点。localhost 拒绝连接”。 screen.屏幕。
I feel like I am missing something small that's causing this to happen.我觉得我错过了导致这种情况发生的一些小事情。 I can't seem to find any solutions online.
我似乎无法在网上找到任何解决方案。
I think the problem is about your firewall.我认为问题出在您的防火墙上。
Check the link https://www.hostinger.com/tutorials/localhost-refused-to-connect-error#:~:text=Subscribe-,What%20Is%20the%20Localhost%20Refused%20to%20Connect%20Error%3F,Apache%20webserver%20not%20running%20properly.检查链接https://www.hostinger.com/tutorials/localhost-refused-to-connect-error#:~:text=Subscribe-,What%20Is%20the%20Localhost%20Refused%20to%20Connect%20Error%3F ,Apache%20webserver%20not%20running%20正确。
And this localhost refused to connect Error in visual studio而这个localhost 拒绝连接 Visual Studio 中的错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.