繁体   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