如何更改 Asp.Net 核心应用程序的端口号? [英] How to change the port number for Asp.Net core app?

查看:38
本文介绍了如何更改 Asp.Net 核心应用程序的端口号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 project.json 中添加了以下部分.

I added the following section in project.json.

  "commands": {
    "run": "run server.urls=http://localhost:8082",
    "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:8082",
    "weblistener": "Microsoft.AspNet.Hosting --server WebListener --server.urls http://localhost:8082"
  },

但是,使用 http://localhost:5000">dotnet myapp.dll?

However, it still shows "Now listening on: http://localhost:5000" when run it using dotnet myapp.dll?

顺便说一句,来自其他机器的客户端是否能够访问该服务?

BTW, will clients from other machine be able to access the service?

推荐答案

是的,如果您绑定到任何外部 IP 地址,这将可以从其他机器访问.例如绑定到 http://*:80 .请注意,绑定到 http://localhost:80 只会绑定在 127.0.0.1 接口上,因此其他机器无法访问.

Yes this will be accesible from other machines if you bind on any external IP address. For example binding to http://*:80 . Note that binding to http://localhost:80 will only bind on 127.0.0.1 interface and therefore will not be accesible from other machines.

Visual Studio 正在覆盖您的端口.您可以更改 VS 端口编辑此文件 PropertieslaunchSettings.json 或通过代码设置:

Visual Studio is overriding your port. You can change VS port editing this file PropertieslaunchSettings.json or else set it by code:

        var host = new WebHostBuilder()
            .UseKestrel()
            .UseContentRoot(Directory.GetCurrentDirectory())
            .UseIISIntegration()
            .UseStartup<Startup>()
            .UseUrls("http://localhost:80") // <-----
            .Build();

        host.Run();

使用外部配置文件的分步指南可用 此处.

A step by step guide using an external config file is available here.

这篇关于如何更改 Asp.Net 核心应用程序的端口号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆