LaunchSettings.json中的Asp.Net Core更改URL不起作用

标签 asp.net asp.net-mvc asp.net-core asp.net-core-mvc

当我将网站作为控制台应用程序运行时,我想更改默认URL(http://localhost:5000)。

我编辑了launchSettings.json但它不起作用...它仍然使用端口5000:

    {
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:4230/",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "website": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "http://localhost:80",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

最佳答案

生成“BuildWebHost”时,需要添加URL。希望这对您有帮助https://github.com/aspnet/KestrelHttpServer/issues/639

以下是我在.net core 2.0控制台应用程序中使用的代码

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

    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .UseUrls("http://localhost:5050/")
            .Build();


}

Screenshot of the console output

关于LaunchSettings.json中的Asp.Net Core更改URL不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38314636/

相关文章:

html - ASP.Net Bundle CSS 样式

c# - 将参数发送到另一个 ASP.Net 页面

asp.net-mvc - 具有行跨度的 ASP.NET MVC Razor 设计表

c# - 在 Visual Studio Code 中恢复依赖项使用了错误的源/提要

c# - 使用 aspnetcore 2.2 联合 Azure AD 登录后,User.Identity.Name 为空

asp.net - Razor View 中的 div 颜色

asp.net - 安装 Ninject.MVC5 后出现 FileLoadException

c# - 基于身份声明的动态数据库连接字符串

asp.net-mvc - ASP.NET MVC应用程序中的错误

javascript - 如何自定义一个javascript文件