【问题标题】:Angular starts random ports even using the same config即使使用相同的配置,Angular 也会启动随机端口
【发布时间】:2021-02-14 01:21:13
【问题描述】:

我有一个基于 ASP.NET Core 的 Angular 应用程序,但有时在使用 dotnet watch run 命令重新启动应用程序后,它开始使用不同的端口,但我的启动端口在 launchSetting.json 文件中定义为之前的:

"applicationUrl": "https://localhost:5001;http://localhost:5000",

我还终止了使用这些端口的进程并重新启动应用程序,但它使用的是随机端口。这正常吗?

【问题讨论】:

    标签: angular asp.net-core .net-core


    【解决方案1】:

    注意:这个问题也可能是url参数中使用https引起的。将 url 参数更改为 http 并在应用其他方法之前重试。 Chrome 可能正在尝试连接到 HTTPS,但您没有启用 HTTPS 的 IIS Express 设置。

    如果你想用VS Code的方式来做,只要用F5(或者运行>“开始调试”命令),只要把launch.json文件改成这样就很简单了:

    ...
    "env": {
        "ASPNETCORE_ENVIRONMENT": "Development",
        "ASPNETCORE_URLS": "http://localhost:5001"
    },
    ...
    

    否则,如果您使用 IIS Express 配置文件,请编辑您的 launchSettings.json 文件以指定端口:

    "iisSettings": {
      "iisExpress": {
        "applicationUrl": "http://localhost:5001",
      }
    },
    "profiles" : { ... }
    

    有关 ASP.NET Core launchSettings.json 文件的更多信息: https://dotnettutorials.net/lesson/asp-net-core-launchsettings-json-file/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-12
      • 2020-05-11
      • 2017-05-12
      • 1970-01-01
      • 1970-01-01
      • 2021-10-06
      相关资源
      最近更新 更多