【问题标题】:.NET Core 3.0 - Custom docker url being ignored.NET Core 3.0 - 自定义 docker url 被忽略
【发布时间】:2021-05-11 14:04:35
【问题描述】:

我需要一个使用特定自定义 url 运行的 docker 容器。

需要如下:

localhost:9000/sample/

我已经在我的 launchsettings.json 文件中定义了这个:

 "Docker": {
        "commandName": "Docker",
        "launchBrowser": true,
        "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/sample/",
        "publishAllPorts": true,
        "httpPort": 9000
    }

但是当我运行容器并在浏览器中启动它时,它总是会遗漏“样本”,看起来像这样:

localhost:9000

我尝试在 launchsettings.json 中使用以下内容:

 "Docker": {
        "commandName": "Docker",
        "launchBrowser": true,
        "launchUrl": "http://localhost:9000/sample/",
        "publishAllPorts": true,
        "httpPort": 9000
    }

但它仍然只使用 localhost:9000 启动

我在这里错过了什么?

我正在使用 Visual Studio 2019。

【问题讨论】:

  • 尝试在Run With>Custom Configuration > Run Action --> Debug .Net Core Debugger更改启动网址

标签: docker asp.net-core docker-desktop


【解决方案1】:

在您的 startup.cs 中,您可以添加以下行:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
   app.UsePathBase("/sample");
}

https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.usepathbaseextensions.usepathbase?view=aspnetcore-3.0

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-12
    • 1970-01-01
    • 2010-09-10
    • 2014-10-09
    • 2013-10-10
    • 2021-05-13
    • 2010-10-04
    • 2017-05-12
    相关资源
    最近更新 更多