【问题标题】:Visual Studio Code debugger for ASP.NET Core 2 don't work with different portASP.NET Core 2 的 Visual Studio Code 调试器不适用于不同的端口
【发布时间】:2018-07-21 04:33:48
【问题描述】:

我的目的是使用与默认 5000 不同的端口启动 VSCode 调试器,为此我在“args”数组(命令行参数)和 ASPNETCORE_URLS env 变量中都指定了 url。我正在为 Visual Studio Code 调试器使用以下 launch.json 配置:

{
   // Use IntelliSense to find out which attributes exist for C# debugging
   // Use hover for the description of the existing attributes
   // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
   "version": "0.2.0",
   "configurations": [
        {
            "name": ".NET Core Launch (web)",
            "type": "coreclr",
            "request": "launch",
            "preLaunchTask": "build",
            // If you have changed target frameworks, make sure to update the program path.
            "program": "${workspaceFolder}/MotelsBack.API/bin/Debug/netcoreapp2.0/MotelsBack.API.dll",
            "args": ["urls=http://localhost:6000"],
            "cwd": "${workspaceFolder}/MotelsBack.API",
            "stopAtEntry": false,
            "internalConsoleOptions": "openOnSessionStart",
            "launchBrowser": {
                "enabled": true,
                "args": "${auto-detect-url}",
                "windows": {
                    "command": "cmd.exe",
                    "args": "/C start ${auto-detect-url}"
                },
                "osx": {
                    "command": "open"
                },
                "linux": {
                    "command": "xdg-open"
                }
            },
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development",
                //"ASPNETCORE_URLS": "http://localhost:6000" --Commented, however this don't work also
            },
            "sourceFileMap": {
                "/Views": "${workspaceFolder}/Views"
            }
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}

调试器在指定端口启动,显示如下:

debugger output image

调试器输出表明可以通过我在前面两个选项中指定的 url 访问应用程序,但是当我从任何资源管理器访问此 url 时,应用程序无法访问,它只是不起作用,但如果我删除来自launch.json的端口定义使用它工作的5000默认端口。

Visual Studio Code 调试器不接受不同的端口?

【问题讨论】:

    标签: c# debugging asp.net-core visual-studio-code .net-core


    【解决方案1】:

    端口 6000 是浏览器认为不安全的端口,因此 safari 和 chrome 不会连接到它们(WebKitErrorDomain:103 on safari 和 ERR_UNSAFE_PORT on chrome)。

    ASPNETCORE_URLS 环境变量使用不同的、非“不安全”的端口,它应该可以工作。

    通过--urls 传递它目前在 ASP.NET Core 2.0 中是不可能的,但由于this issue 将在 2.1 中(请参阅问题以了解解决方法)。

    【讨论】:

    • 是的,使用那个不安全的端口是我的错误,我已更改为 5500,现在它可以工作了。对于任何想通过命令行传递参数的人,可以使用var configuration = new ConfigurationBuilder().AddCommandLine(args).Build(); 并在WebHost.CreateDefaultBuilder(args) 中使用它作为参数传递:UseConfiguration(configuration)
    猜你喜欢
    • 2018-11-27
    • 2019-06-27
    • 2021-09-28
    • 2020-11-09
    • 2017-07-30
    • 2016-07-14
    • 1970-01-01
    • 1970-01-01
    • 2022-01-21
    相关资源
    最近更新 更多