Visual Studio Codespaces中的ASP.NET Core应用程序调试问题

we

我在Visual Studio Codespaces中创建了一个ASP.NET Core应用程序。我在项目中添加了Visual Studio Code的C#,当我运行该应用程序时,我没有重定向到本地Web应用程序。我有一个HTTP错误504。在此处输入图片说明

该页面阻止了重定向。 在此处输入图片说明

然后HTTP错误504。 在此处输入图片说明

我的启动设置是在端口5001和5000上配置的:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:55448",
      "sslPort": 44383
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "Test": {
      "commandName": "Project",
      "launchBrowser": true,
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

默认情况下,Visual Studio Code的Codespace中转发的端口为:

在此处输入图片说明

为什么我无法通过地址http:// localhost:5000访问Web应用程序?

编辑:

.vscode / 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}/Test/bin/Debug/netcoreapp3.1/Test.dll",
            "args": [],
            "cwd": "${workspaceFolder}/Test",
            "stopAtEntry": false,
            // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
            "serverReadyAction": {
                "action": "openExternally",
                "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
            },
            "env": {
                "ASPNETCORE_ENVIRONMENT": "Development"
            },
            "sourceFileMap": {
                "/Views": "${workspaceFolder}/Views"
            }
        },
        {
            "name": ".NET Core Attach",
            "type": "coreclr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}

.vscode / task.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "dotnet",
            "type": "process",
            "args": [
                "build",
                "${workspaceFolder}/Test/Test.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "publish",
            "command": "dotnet",
            "type": "process",
            "args": [
                "publish",
                "${workspaceFolder}/Test/Test.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        },
        {
            "label": "watch",
            "command": "dotnet",
            "type": "process",
            "args": [
                "watch",
                "run",
                "${workspaceFolder}/Test/Test.csproj",
                "/property:GenerateFullPaths=true",
                "/consoleloggerparameters:NoSummary"
            ],
            "problemMatcher": "$msCompile"
        }
    ]
}

此外,如果我在VS Code中打开Codespace并在本地VS Code上运行它,则它可以正常工作。 在此处输入图片说明 在此处输入图片说明 在此处输入图片说明 在此处输入图片说明

吼S.

在本地使用VS Code时,不使用launchSettings.json。在VS Code中安装C#扩展名时,选择.NET Core启动时我得到了.vscode / launch.json和.vscode / tasks.json(我的应用程序称为“ WebApplication”)。

.vscode / launch.json(已更新为工作设置)

{
"version": "0.2.0",
"configurations": [
    {
        "name": ".NET Core Launch (web)",
        "type": "coreclr",
        "request": "launch",
        "preLaunchTask": "build",
        "program": "${workspaceFolder}/bin/Debug/netcoreapp3.1/WebApplication.dll",
        "args": [],
        "cwd": "${workspaceFolder}",
        "stopAtEntry": false,
        "serverReadyAction": {
            "action": "openExternally",
            "pattern": "\\bNow listening on:\\s+(http?://\\S+)"
        },
        "env": {
            "ASPNETCORE_ENVIRONMENT": "Development"
        },
        "sourceFileMap": {
            "/Views": "${workspaceFolder}/Views"
        }
    },
    {
        "name": ".NET Core Attach",
        "type": "coreclr",
        "request": "attach",
        "processId": "${command:pickProcess}"
    }
]
}

.vscode / tasks.json

{
"version": "2.0.0",
"tasks": [
    {
        "label": "build",
        "command": "dotnet",
        "type": "process",
        "args": [
            "build",
            "${workspaceFolder}/WebApplication.csproj",
            "/property:GenerateFullPaths=true",
            "/consoleloggerparameters:NoSummary"
        ],
        "problemMatcher": "$msCompile"
    },
    {
        "label": "publish",
        "command": "dotnet",
        "type": "process",
        "args": [
            "publish",
            "${workspaceFolder}/WebApplication.csproj",
            "/property:GenerateFullPaths=true",
            "/consoleloggerparameters:NoSummary"
        ],
        "problemMatcher": "$msCompile"
    },
    {
        "label": "watch",
        "command": "dotnet",
        "type": "process",
        "args": [
            "watch",
            "run",
            "${workspaceFolder}/WebApplication.csproj",
            "/property:GenerateFullPaths=true",
            "/consoleloggerparameters:NoSummary"
        ],
        "problemMatcher": "$msCompile"
    }
]
}

选择.NET Core启动来运行应用程序时,Chrome会使用http:// localhost:5000打开该应用程序,然后由于以下原因将其重定向到https:// localhost:5001

app.UseHttpsRedirection();

在我的配置中。

也许尝试从VS Code在本地运行该应用程序以查看是否可行?我还没有一个帐户可以在Codespaces中对此进行测试,对此感到抱歉。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在Visual Studio中调试对.NET Core应用程序的编辑不会生效

Visual Studio 2017中的Docker ASP.NET CORE 2.1应用程序。该应用程序无法在调试模式下启动

Visual Studio 2017中的空白ASP .NET Core Web应用程序项目

Visual Studio 2017“ASP.NET Core Web 应用程序(.NET Core)”模板丢失

使用为Microsoft Edge配置的Visual Studio 2019进行调试时,ASP.NET Core应用程序的调试和开发?

调试 Web 应用程序 Visual Studio 重定向到我的 ASP.NET 应用程序

Visual Studio运行.NET应用程序中的调试日志文件位置

我们如何在Visual Studio Code中调试ASP.NET MVC Web应用程序?

如何调试从Visual Studio 2017在Minikube上运行的.Net Core应用程序

创建F#ASP.NET Core Web应用程序需要哪种Visual Studio 2017选项?

Visual Studio 15上不存在ASP.NET Core Web应用程序模板

将命令行参数传递给 Visual Studio 容器工具中 .NET Core 控制台应用程序的 Docker 调试运行

ASP.NET Core-在Visual Studio 2015中通过Docker调试时出现的问题

无法在Visual Studio 2019中调试Asp.Net Core 2.1 Angular应用

从Docker Windows容器远程调试.Net Core Console应用程序时,Visual Studio 2017不会加载调试符号

使用Visual Studio IIS Express将VSCode调试器附加到.NET Core应用程序调试

如何调试引用Visual Studio 2019中的.NET Framework 4.8类库的.NET 5 WinForms应用程序

如何使用SpaTemplates向Visual Studio 2017中的ASP.NET Core Angular 2应用程序添加很棒的字体

ASP.Net Core应用程序可在Visual Studio中运行,但不能与dotnet运行

如何在Visual Studio for Mac中打开预先存在的.NET Core应用程序?

新的ASP.Net Core Web应用程序屏幕中没有ASP.Net Core模板Visual Studio 2017

Visual Studio 2012中“ /”应用程序中的ASP.NET服务器错误

Javascript断点在Visual Studio 2019 asp.net应用程序中不起作用

是否可以在Mac的Visual Studio中开发ASP.NET MVC应用程序?

在Visual Studio代码中运行asp.net核心mvc应用程序

在 Visual Studio 中调试 Windows 应用程序

无法在Visual Studio 2019中将程序集添加到.Net Core应用程序

如何在Visual Studio中使用ASP.NET Core Web应用程序-API项目托管网页?

如何在带有Polymer的Visual Studio ASP.NET Core应用程序中使用照明元素