Configure launchSettings.json for SSL in debug - ASP.NET Core / Visual Studio Code

21,943

Solution 1

If you don't want to change your Program.cs file just for debugging in VS Code, you can also configure the urls in your launch.json. You need to specify the urls in the env property. As xneg said you'll need to set up a self-signed cert to do this.

You can configure the http url and the https (SSL) url

"configurations":[
    {
        ...
        "env": {
            "ASPNETCORE_ENVIRONMENT": "Development",
            "ASPNETCORE_URLS": "http://localhost:5002;https://localhost:5003"
        },
        ...
    }

The documentation for Kestrel was helpful in figuring this out.

Solution 2

I made the following edits to launchSettings.json on windows and it did the trick. Currently this is the only way to do it in Visual Studio 2017 RC .

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:50183/",
      "sslPort": 44318
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "https://localhost:44318",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "corePostgresIdentity": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:44318"
    }
  }
}

Solution 3

When you run your ASP.NET Core app in VS Code you run it with Kestrel not IIS. You need to setup Kestrel to enable SSL manualy like this (in Program.cs):

public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
            .UseKestrel(options =>
            {
                options.Listen(IPAddress.Loopback, 5000, listenOptions =>
                {
                    listenOptions.UseHttps("localhost.pfx", "yourPassword");
                });
            })
            .UseUrls("https://localhost:5000")
            .Build();

How to create a self-signed certificate is described in this great article.

Solution 4

Usually when you modify the properties for your project, changes are persisted in launchSettings.json. So you need to change launchSettings.json like below:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:8837/",
      "sslPort": 0 //Add ssl port here
    }
  },
 "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "launchUrl": "https://localhost:8837",
      "environmentVariables": {
      "ASPNETCORE_ENVIRONMENT": "Development"
     }
},
Share:
21,943
Jeff Gardner
Author by

Jeff Gardner

Updated on July 09, 2022

Comments

  • Jeff Gardner
    Jeff Gardner almost 2 years

    I am following this tutorial to add Facebook authentication to my web app.

    As part of the process I am trying to enable SSL on my project but everything I have found involves updating a setting in the Project Properties dialog in Visual Studio, which is unavailable to me through Visual Studio Code on my Mac. I've tried updating the values in launchSettings.json manually, but I haven't had any luck.

    How do I update launchSettings.json (or other project files) in Visual Studio Code to enable SSL while debugging?