【问题标题】:How to change the IP and port number for Asp core web app running with kestrel after publishing?发布后如何更改使用红隼运行的 Asp 核心 Web 应用程序的 IP 和端口号?
【发布时间】:2020-08-07 15:55:40
【问题描述】:

为了找到这个问题的答案,我进行了很多搜索。

如何更改运行的 Asp 核心应用程序的 IP 和端口号 红隼?

如您所知,我们使用这样的地址构建和调试 AspCore 应用程序

http://localhost:5000

但是如何在发布后将它更改为这样的内容以便通过网络访问: http://192.168.1.12:80 或更简单,因为不需要写 80 http://192.168.1.12(80 是默认值,但应提及其他端口)

【问题讨论】:

    标签: c# asp.net .net-core kestrel


    【解决方案1】:

    由于我找不到完整的分步解决方案,因此我与社区分享我的经验。

    希望对你有所帮助。

    这就是答案:

    在您的服务器中,您应该以 admin

    身份打开 CMD

    然后运行这段代码:

    netsh advfirewall firewall add rule name="Http Port 80" dir=in action=allow protocol=TCP localport=80
    

    接下来在 发布文件夹中的 appsettings.json添加这些代码

    "AllowedHosts": "*",
       "Kestrel": {
        "EndPoints": {
          "Http": {
            "Url": "http://192.168.1.12:80"
          }
        }
      }
    

    现在你的 appsettings.json 必须变成这样:

    {
      "ConnectionStrings": {
        "DefaultConnection": "Server=.\\;Database=MyDbName;Trusted_Connection=True;MultipleActiveResultSets=true"
      },
      "Logging": {
        "LogLevel": {
          "Default": "Information",
          "Microsoft": "Warning",
          "Microsoft.Hosting.Lifetime": "Information"
        }
      },
      "AllowedHosts": "*",
       "Kestrel": {
        "EndPoints": {
          "Http": {
            "Url": "http://192.168.1.12:80"
          }
        }
      }
    }
    

    请考虑您可以更改IP端口号以上只是示例。

    而且您设置的 Ip 必须与服务器 Ip Adderss 相同。

    你应该在那里改变它们:

    现在你可以通过网络访问这个IP了

    http://192.168.1.12:80http://192.168.1.12

    【讨论】:

      猜你喜欢
      • 2016-12-09
      • 2020-04-23
      • 2022-01-11
      • 2019-06-16
      • 2019-12-05
      • 2022-12-09
      • 2018-10-04
      • 2012-09-17
      相关资源
      最近更新 更多