Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2017 Enable SSL

How do you enable SSL for a project in Visual Studio 2017?

In VS15, I could select Project -> Properties -> Debug -> Enable SSL. This option is not available in VS2017. Where has it moved to?

Edit:

I've even tried editing .\vs\config\applicationhost.config to no avail:

        <listenerAdapters>             <add name="http" />             <add name="https" />         </listenerAdapters>          <sites>             <site name="WebSite1" id="1" serverAutoStart="true">                 <application path="/">                     <virtualDirectory path="/" physicalPath="%IIS_SITES_HOME%\WebSite1" />                 </application>                 <bindings>                     <binding protocol="http" bindingInformation=":8080:localhost" />                 </bindings>             </site>             <site name="Filters" id="2">                 <application path="/" applicationPool="Clr4IntegratedAppPool">                     <virtualDirectory path="/" physicalPath="c:\Users\Ashley\documents\visual studio 2017\Projects\Filters\src\Filters" />                 </application>                 <bindings>                     <binding protocol="http" bindingInformation="*:51107:localhost" />                     <binding protocol="https" bindingInformation="*:43107:localhost" />                 </bindings>             </site>             <siteDefaults>                 <logFile logFormat="W3C" directory="%IIS_USER_HOME%\Logs" />                 <traceFailedRequestsLogging directory="%IIS_USER_HOME%\TraceLogFiles" enabled="true" maxLogFileSizeKB="1024" />             </siteDefaults>             <applicationDefaults applicationPool="Clr4IntegratedAppPool" />             <virtualDirectoryDefaults allowSubDirConfig="true" />         </sites>          <webLimits /> 

Edit:

Another option I've tried, which just feels clunky, and kind of defeats the point of an IDE, is to configure Kestrel to use HTTPS. This isn't ideal since I had to export a copy of a certificate for localhost from IIS, and IIS Express still tries to load the site on a different port.

public class Program {     public static void Main(string[] args)     {         var host = new WebHostBuilder()             .UseKestrel(options =>                 options.UseHttps(new X509Certificate2("path/to/cert.pfx", "password")))             .UseContentRoot(Directory.GetCurrentDirectory())             .UseUrls("http://localhost:5100", "https://localhost:4300")             .UseIISIntegration()             .UseStartup<Startup>()             .Build();          host.Run();     } } 

Sadly, this doesn't work when run from VS17. The first time around I got a 502.2 (I think) error, now all I get is an unable to connect error in Chrome. I can run dotnet run from PowerShell and it works fine.

As a workaround, it does the trick. But it doesn't seem neat.

like image 785
Ashley Bye Avatar asked Dec 10 '16 12:12

Ashley Bye


People also ask

How do I enable SSL certificate in Visual Studio?

How to Enable SSL in Visual Studio Development Server? In the Solution Explorer click on the WebAPIEnableHTTP Web API project and press F4 key on the keyboard which will open the Project Properties window. From the Project Properties window, we need to set the SSL Enabled property to true.

How do I fix SSL TLS issues in Visual Studio 2017?

Open Visual Studio and open the solution containing the web project you'd like to run in IIS Express with SSL. Verify that SSL Enabled is set to True . If you are working with a web project for which SSL has not yet been enabled, set SSL Enabled to True .

How do I trust an SSL certificate in Visual Studio 2019?

In the Certificate Import Wizard, browse to the certificate that you exported (Trusted Root Certification Authorities), and then select Place all certificates in the following store. Click Next, verify that you selected the correct certificate, and then click Finish.


1 Answers

Ports are locked down in IIS Express so that it doesn't have to be run as Administrator...

Valid Ports are 44300 - 44399

Check out the Dev Community article https://developercommunity.visualstudio.com/content/problem/39430/changing-port-number-in-a-web-project-does-not-imm.html

You can edit launchSettings.json, but the ssl ports must fall in this range.

like image 133
Mike Kushner Avatar answered Oct 03 '22 15:10

Mike Kushner