56

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.

Ashley Bye
  • 1,752
  • 2
  • 23
  • 40
  • Seemingly this has changed in recent updates to Visual Studio 2017 RC? I do see the Enable SSL option, and using it worked for fine for me. I did have to [set up my account to trust IIS certificates](https://blogs.msdn.microsoft.com/robert_mcmurray/2013/11/15/how-to-trust-the-iis-express-self-signed-certificate/). – Steven Jeuris Feb 13 '17 at 23:10
  • See this question also: https://stackoverflow.com/questions/43886818/enabling-ssl-in-visual-studio-2017 – oatsoda Feb 11 '19 at 11:09

10 Answers10

80

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.

Mike Kushner
  • 959
  • 9
  • 14
  • 4
    This is the right answer. I picked a random port not in that range, and it does not work. Get one in that range - it works! Thanks for the help. – Eric Wild Nov 06 '17 at 19:37
  • 1
    Agreed, if you were setup to use http first, VS doesn't change the port number for you. Changing the Project Url value to include a port above 44300 worked for me. --> https://localhost:44301/ – Mike Devenney Jan 19 '18 at 20:09
  • After half a day searching the web I found your answer, thanks! This solved my issue! – Filippo Agostini Jul 21 '18 at 16:15
  • Yep, @ashley-bye should tag this as the answer so it helps others too – Mike Kushner Oct 27 '18 at 16:57
  • 1
    This is a terrible answer. It doesn't explain how to actually set the port number, just that it has to be in a range. Most of the 'content' comes from a link, making it a link-only answer, except the link doesn't answer the question either. – GreySage Nov 14 '19 at 17:58
  • Amazing... Go Figure it out there Sage... It's pretty simple. – Mike Kushner Nov 26 '19 at 22:28
61

This is for an Asp.Net MVC .Net Framework Project

  1. Select your Project by highlighting it.
  2. Then hit F4 to open its Properties pane.
  3. Find the SSL Enabled item on list and set its value to True, and copy SSL URL value onto your clipboard.
  4. Whilst your Project is highlighted, hit Alt + Enter to open the Properties dialogue - paste the copied SSL URL into the project url under the Web menu input box.
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
user9410863
  • 755
  • 6
  • 4
  • 7
    I would like to add that if the option seems to be _greyed out_ it most likely is because iis process is still running (even after you stop the debugging session from VS). Just kill the process in the Task Manager and it will let you change the value. – tfrascaroli Apr 23 '18 at 14:58
  • This is the only solution that worked for me! Thank you! – Arad Alvand Jun 25 '19 at 19:47
  • 2
    This isn't a solution. in VS2017 the Properties menu *doesn't have* a Web menu input box, so you obviously can't enter anything there. – GreySage Nov 14 '19 at 18:01
  • 2
    "This site can't be reached" - fantastic – Murphybro2 Mar 04 '20 at 15:57
14

For Visual Studio 2019 and 2017:

  1. In Solution Explorer, right click the project > Properties
  2. Select the Debug Tab
  3. Check Enable SSL enter image description here
RickAndMSFT
  • 20,912
  • 8
  • 60
  • 78
6

In Solution Explorer right click on your website name and select "Properties Window", or simply hit F4. Under the Developer Web Server section change SSL Enabled from False to True.

user44129
  • 71
  • 1
  • 7
5

For those running asp.net core 1.x in Visual Studio 2017 RC, you should be able to change the "sslPort": 0 line in the launchSettings.json file to whatever port number you would like to use for SSL. This effectively changes the bindings in the .\vs\config\applicationhost.config file mentioned in the previous answers.

MaxT
  • 261
  • 3
  • 8
4

This is for an Asp.Net Core 2.0:

  1. Open up your Solution Explorer in VS2017.
  2. Doubleclick Properties (yes, it's an object itself too, not just a folder)
  3. Open Debug on the left side
  4. Scroll down and select Enable SSL

If it's already enabled, open up launchSettings.json (unfold Properties) and set "sslPort" to 0, then do the steps again.

VS2017 should now ask you if you want to add an SSL certificate (something it doesn't do if you changed launchSettings.json on your own) and it'll set a port for you.

DavidHulsman
  • 360
  • 1
  • 2
  • 9
3

Editing the .\vs\config\applicationhost.config actually worked for me.

<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>

It does however load the app up in the browser using the non-https port by default. If you manually point your browser to the 43107 port it should work.

Edit

This worked for me a few times but stopped working. Subsequent testing revealed that whenever I would click the button to start debugging in VS 2017 RC it would remove the binding I manually added.

I fixed that by making the file read-only now it's starting with HTTPS support again.

Yoh Deadfall
  • 2,711
  • 7
  • 28
  • 32
NightWatchman
  • 1,217
  • 5
  • 17
  • 25
  • Still a bit of a "hacky" workaround, but I'll try making the file read-only to prevent overwriting of configuration options. At least I should be able to run everything from within VS again. – Ashley Bye Dec 23 '16 at 09:05
  • 1
    If you want to avoid the "hacky" workaround then: 1. On the Solution Explorer open the properties for your application. 2. Select Debug. 3. Enable SSL. – Allan Jul 16 '17 at 00:41
  • @Allan You should add that as an answer so I can accept it. At the time this question was written Microsoft hadn't implemented that option yet, but going forward it seems to be the best option. – NightWatchman Jul 17 '17 at 17:57
  • "Enable SSL" doesn't work, unfortunately. This hack is the only thing that worked for me. It used to work, but VS2017 has had "upgrades" that broke this again since this post was made (August 2018). – MC9000 Sep 02 '18 at 13:26
3

Property Settings

I unfortunately had the same issue, couldn't see the "enable SSL" checkbox in the Debug tab of the Project's properties... Finally found it! --> Set the launch on "IIS Express", then you will be able to select it ;-)

oatsoda
  • 2,088
  • 2
  • 26
  • 49
1

One important point you may be missing is that you have to Run Visual Studio as adminsitrator (right vlick VS icon and select 'Run as Administrator'. I have been strugling with this SSL problem and after by running VS as adminstrator I made it work.

0

If you see the SSL Enabled option under the project's Properties window, but it is greyed out

  1. Close Visual Studio
  2. Edit the vwd.webinfo file and add the sslPort="44317" attribute to the iisExpressSettings element.
  3. Alternatively, you can delete the vwd.webinfo file and Visual Studio will create a new one when you open the project
Michael
  • 2,825
  • 3
  • 24
  • 30