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

查看:256
本文介绍了如何更改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端口,然后编辑此文件 Properties\launchSettings.json 或通过代码进行设置:

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

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

        host.Run();

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

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

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

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