Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 905
Jeff Gardner Avatar asked Dec 21 '16 05:12

Jeff Gardner


3 Answers

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.

like image 121
Brad Lawrence Avatar answered Oct 08 '22 18:10

Brad Lawrence


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"
    }
  }
}
like image 9
Sam Sippe Avatar answered Oct 08 '22 18:10

Sam Sippe


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.

like image 2
xneg Avatar answered Oct 08 '22 19:10

xneg