使用 dotnet new webapi 构建默认的.NET Core 2.1 WebAPI项目,并通过VSCode生成默认 launch.json ,当从VSCode运行项目时,浏览器将启动并自动导航到http://localhost:5000/,但是在更改代码时仅使用HTTP在不同的默认端口上:

Program.cs中

public class Program {
    public static void Main(string[] args) {
      CreateWebHostBuilder(args).Build().Run();
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
      WebHost.CreateDefaultBuilder(args)
        .UseUrls("http://*:5080")
        .UseStartup<Startup>();
  }

Startup.cs

public class Startup {
    public Startup(IConfiguration configuration) {
      Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services) {
      services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
      if (env.IsDevelopment()) {
        app.UseDeveloperExceptionPage();
      }
      app.UseMvc();
    }
  }

当项目从VSCode运行时,浏览器启动并自动导航到http://[::]:5080/而不是http://localhost:5080/有没有人知道为什么会发生这种情况以及如何修复它?我想允许通过localhost,机器名和/或IP地址(虚拟或其他)访问 . 似乎 $ 感到困惑......