Visual Studio 2017启用SSL

Ash*_*Bye 45 ssl https kestrel-http-server visual-studio-2017

如何在Visual Studio 2017中为项目启用SSL?

在VS15中,我可以选择Project - > Properties - > Debug - > Enable SSL.VS2017中不提供此选项.它搬到了哪里?

编辑:

我甚至尝试过编辑.\vs\config\applicationhost.config无济于事:

        <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 />
Run Code Online (Sandbox Code Playgroud)

编辑:

我尝试过的另一种选择,就是让人感到笨拙,并且有点像IDE一样,就是配置Kestrel来使用HTTPS.这不太理想,因为我必须从IIS导出localhost的证书副本,并且IIS Express仍尝试在不同的端口上加载该站点.

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();
    }
}
Run Code Online (Sandbox Code Playgroud)

可悲的是,从VS17运行时,这不起作用.我第一次遇到502.2(我认为)错误,现在我得到的是Chrome无法连接错误.我可以dotnet run从PowerShell 运行,它工作正常.

作为一种解决方法,它可以解决问题.但它似乎并不整洁.

小智 53

端口在IIS Express中被锁定,因此不必以管理员身份运行...

有效端口是44300 - 44399

查看开发社区文章 https://developercommunity.visualstudio.com/content/problem/39430/changing-port-number-in-a-web-project-does-not-imm.html

您可以编辑launchSettings.json,但ssl端口必须在此范围内.

  • 这是正确的答案.我选择了一个不在该范围内的随机端口,但它不起作用.获得该范围内的一个 - 它的工作原理!谢谢您的帮助. (3认同)

小智 48

这是针对Asp.Net MVC .Net Framework项目的

  1. 通过突出显示选择您的项目.
  2. 然后单击F4以打开其"属性"窗格.
  3. 在列表中找到SSL Enabled项,并将其值设置为True,并将SSL URL值复制到剪贴板上.
  4. 虽然你的项目被突出显示,命中Alt+ Enter,打开属性对话框-复制粘贴SSL URL到根据项目URL 的网页菜单输入框.

  • 我想补充一点,如果选项似乎被_greyed out_它很可能是因为iis进程仍在运行(即使你从VS停止调试会话).只需在任务管理器中终止该过程,它就会让您更改该值. (5认同)
  • 这不是一个解决方案。在 VS2017 中,属性菜单*没有* Web 菜单输入框,因此您显然无法在那里输入任何内容。 (2认同)
  • “无法访问此网站” - 太棒了 (2认同)

Ric*_*SFT 11

对于Visual Studio 2017:

  1. 在解决方案资源管理器中,右键单击项目> 属性
  2. 选择" 调试"选项卡
  3. 选中启用S​​SL 在此输入图像描述

  • ASP.NET Core(1.1)项目中不存在此选项,在Web服务器设置下,唯一可用的选项是AppURL文本框 (3认同)
  • 这似乎在 Visual Studio 2019 中消失了 (3认同)
  • VS 2017(.NET 4.7.2 MVC Web 项目)没有“调试”选项卡 (3认同)
  • 这会在该范围内创建一个随机端口号。 (2认同)

小智 5

对于在 Visual Studio 2017 RC 中运行 asp.net core 1.x 的用户,您应该能够将 launchSettings.json 文件中的 "sslPort": 0 行更改为您希望用于 SSL 的任何端口号。这有效地更改了前面答案中提到的 .\vs\config\applicationhost.config 文件中的绑定。


小智 5

在解决方案资源管理器中,右键单击您的网站名称,然后选择“属性窗口”,或直接单击F4。在“开发人员Web服务器”部分下,将“已启用SSL”从False更改为True。

  • ASP.NET Core 1.1项目中没有这样的部分 (3认同)

rus*_*nge 3

编辑.\vs\config\applicationhost.config实际上对我有用。

<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>
Run Code Online (Sandbox Code Playgroud)

但是,它默认使用非 https 端口在浏览器中加载应用程序。如果您手动将浏览器指向 43107 端口,它应该可以工作。

编辑

这对我有用过几次但不再起作用。随后的测试表明,每当我在 VS 2017 RC 中单击按钮开始调试时,它都会删除我手动添加的绑定。

我通过将文件设置为只读来解决这个问题,现在它再次开始支持 HTTPS。