【发布时间】:2019-04-16 05:07:46
【问题描述】:
我已将.net core(2.2) Web 应用程序部署为 Windows 服务,但无法从远程 PC 访问此应用程序。
应用程序在本地计算机上使用 Url = "http://localhost:5000" 正常运行。
我在“launchSettings.json”文件中指定了带有 IP 地址的 Url =“http://XXX.XXX.XX.XX:5000”,但无法从远程 PC 访问它。
出于测试目的,我已经关闭了我的防火墙设置,但它没有任何效果。
Web应用部署环境:Windows7
现有源代码:
launchSetting.json
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:56032",
"sslPort": 44324
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"TestApp": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Program.cs
public static void Main(string[] args)
{
var isService = !(Debugger.IsAttached || args.Contains("--console"));
if (isService)
{
var pathToExe = Process.GetCurrentProcess().MainModule.FileName;
var pathToContentRoot = Path.GetDirectoryName(pathToExe);
Directory.SetCurrentDirectory(pathToContentRoot);
}
var builder = CreateWebHostBuilder(args.Where(arg => arg != "--console").ToArray());
var host = builder.Build();
if (isService)
host.RunAsService();
else
host.Run();
}
预期结果: 能够从远程 PC 访问作为 Web 服务安装的 .net 核心 Web 应用程序。
【问题讨论】:
标签: c# asp.net-core .net-core asp.net-core-2.2