1

I created an ASP.NET Core app in Visual Studio Codespaces. I added C# for Visual Studio Code in the project and when I'm running the application I'm not redirected to the local web application. I have instead an HTTP ERROR 504. enter image description here

The page is blocking the redirection. enter image description here

And then HTTP ERROR 504. enter image description here

My launch settings is configured on port 5001 and 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"
      }
    }
  }
}

And the forwarded ports in Visual Studio Code in Codespace are by default :

enter image description here

Any clue why I can't access the web app via the address http://localhost:5000?

Edit :

.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"
        }
    ]
}

Moreover if I open the Codespace in VS Code and run it on local VS Code, it's working. enter image description here enter image description here enter image description here enter image description here

1 Answer 1

1

When using VS Code locally, launchSettings.json is not used. When installing C# extension in VS Code, I get a .vscode/launch.json and .vscode/tasks.json when selecting .NET Core launch (my app is called "WebApplication").

.vscode/launch.json (updated with working settings)

{
"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"
    }
]
}

When selecting .NET Core launch to run the app, Chrome opens the app with http://localhost:5000 and then gets redirected to https://localhost:5001 because of

app.UseHttpsRedirection();

in my config.

Maybe try to run the app from VS Code locally to see if that works? I don't have an account yet to test this in Codespaces, sorry for that.

Sign up to request clarification or add additional context in comments.

9 Comments

Hi,Tanks for your answer ! I tried it but it doesn't seems to work in my case. Should I configure something else ?
Hi Ewean. Did some testing with VS Code, and updated my answer.
Hello, I checked the files and I have the same content.( .vscode/tasks.json and .vscode/launch.json). However when I'm running in my local Visual Studio Code, it seems to work. I don't why Codespace cannot redirect to my localhost. Moreover, if I keep opening my Local Visual Studio, I can run it from Codespace. So if I need to run and debug my web app, I need to open a local Vs Code ?
This case got me curious, so I fetched my credit card and signed up for Azure. Trying to set up accounts from VS and VS code turned out to be impossible due to recurring error messages. However, my findings so far: If you run your app locally, and then click on the "Port 5000"-link on online.visualstudio.com, you will be redirected to localhost:5000. My experience with cloud stuff is from Kubernetes/OpenShift on AWS, not Azure, but I think it might be impossible to debug code in Azure. I managed to deploy my little example app all the way to production in Azure though.
Thank you ! :) It's working on port 5000. I manage it by commenting app.UseHttpsRedirection();.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.