Visual Studio 2017 Enable SSL

2020-05-15 15:17发布

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.

9条回答
放荡不羁爱自由
2楼-- · 2020-05-15 15:19

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.

查看更多
成全新的幸福
3楼-- · 2020-05-15 15:22

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.

查看更多
放我归山
4楼-- · 2020-05-15 15:26

For Visual Studio 2017:

  1. In Solution Explorer, right click the project > Properties
  2. Select the Debug Tab
  3. Check Enable SSL enter image description here
查看更多
Bombasti
5楼-- · 2020-05-15 15:26

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.

查看更多
beautiful°
6楼-- · 2020-05-15 15:29

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.
查看更多
欢心
7楼-- · 2020-05-15 15:31

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.

查看更多
登录 后发表回答