8

I'm trying to replicate what Visual Studio does on F5 debugging in my .net core api application.

It seems that "dotnet run --project" is the trick that I'm looking for except for one thing:

When I run with F5, it runs on https and it is trusted. When I run with dotnet run, it runs on https and it is NOT trusted.

And I seem to be having problems using the application even though it seems to be running.

Any thoughts? I would like to do the same trick that F5 does just in order to test my application, however dotnet run must be missing some sort of certificate or something?

I really don't want to have to change my source code or to do anything with certs, again, because it is working as designed on F5, just need to do the same trick for dotnet run.

JBoothUA
  • 3,040
  • 3
  • 17
  • 46
  • What editor or IDE are you exactly working on? F5 is handled by many editors. – Alsein Jul 03 '19 at 02:59
  • 1
    @Alsein I think OP's point is more that it runs from Visual Studio (which is supplying its local development SSL certficiate that's registered with the machine), whereas using `dotnet run -https` isn't using this certificate. – ProgrammingLlama Jul 03 '19 at 03:00
  • 1
    Whether it is trusted depends on the browser's trusting policy. So if your IDE passes some arguments when launching the browser to specify a development certificate to be trusted, it would work properly. – Alsein Jul 03 '19 at 03:03
  • @John Then Visual Studio must be explicitly specified by OP. – Alsein Jul 03 '19 at 03:05
  • it is Visual Studio – JBoothUA Jul 03 '19 at 03:09
  • @John is it possible to use that local development SSL certificate from "dotnet run" ? – JBoothUA Jul 03 '19 at 03:10
  • 1
    I've been trying to find that out. So far I've got as far as a [GitHub issue](https://github.com/aspnet/AspNetCore.Docs/issues/6066) about trusting development certs. – ProgrammingLlama Jul 03 '19 at 03:11
  • Try checking what commandline arguments and environment variables are passed to the browser and you would know how to let add a certificate to be trusted. – Alsein Jul 03 '19 at 03:12
  • It looks like it might actually be as simple as running `dotnet dev-certs https --trust`, although i'm not in a position to test this myself at the moment. – ProgrammingLlama Jul 03 '19 at 03:14
  • i gave that a try and it did not work. it seemed to add something for localhost, but had no effect on my application. i must still be missing something – JBoothUA Jul 03 '19 at 03:17
  • OH WOW! I think I got it working. Reading your thread you left, I just had to close all of my browsers. Basically: shut down all browsers: dotnet dev-certs https --clean and then dotnet dev-certs https --trust, seems to have worked! thanks so much! – JBoothUA Jul 03 '19 at 03:23

1 Answers1

11

Based on the documentation here, it seems like you need to install and trust the development certificate:

.NET Core SDK includes a HTTPS development certificate. The certificate is installed as part of the first-run experience.

While the certificate is installed at this stage, it goes on to say that:

Installing the .NET Core SDK installs the ASP.NET Core HTTPS development certificate to the local user certificate store. The certificate has been installed, but it's not trusted. To trust the certificate perform the one-time step to run the dotnet dev-certs tool.

To trust it, you should use the following command:

dotnet dev-certs https --trust

This should show a dialog prompting you to trust the certificate. Once this is done, you can start your project running again, and restart your browsers. This should allow you to access the site on https://localhost:portnumber

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
  • Thanks John! I just want to add to anyone else who is running into this.. If you're still having a problem use the same tool to clear the dev certs. Close all your broswers and try the trust command again. – JBoothUA Jul 04 '19 at 15:16