简体   繁体   English

以 windows 服务运行 web 应用程序时拒绝连接到 localhost

[英]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.我似乎无法在网上找到任何解决方案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Web应用程序调用Web服务时拒绝连接时,可以从本地主机正常工作 - Getting connection refused when calling a web service from a web app works fine from localhost 将ASP.NET Web应用程序连接到Windows Service应用程序 - connect ASP.NET web application to Windows Service application 当请求连接Web服务时,Windows Mobile Pocket PC 2003应用程序“无法解析远程名称”异常 - Windows Mobile Pocket PC 2003 application “remote name cannot be resolved” exception when apppemt to connect web service 如何编写Web服务以将MySQL连接到Windows应用商店? - How to write a web service to connect MySQL to a windows store application? 在调试器中运行的应用程序连接到Web服务,但作为Windows Service运行时不连接 - Application running in debugger connects to webservice in but not when running as windows service 通过Windows服务访问在本地主机上运行的Lync的当前实例时,出现异常“主机进程未运行” - When accessing current instance of Lync running on localhost by Windows service, I get the exception “host process is not running” 作为Windows服务运行时,MSMQ应用程序不处理排队的消息 - MSMQ Application does not process queued messages when running as Windows Service 代码在控制台应用程序中有效,但在Windows Service中运行时不起作用 - Code works in a console application, but does not work when running in windows service 当网站未作为网络服务运行时,应用程序池崩溃 - Application Pool Crashes when Web Site is Not Running as Network Service 将应用程序作为Windows服务运行时的汇编文件加载错误 - assembly file load error when running application as windows service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM