Visual Studio的2017年启用SSL

问题描述 投票:43回答:9

如何启用在Visual Studio 2017年一期工程SSL?

在VS15,我可以选择项目 - >属性 - >调试 - >启用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 />

编辑:

我试过另一种选择,它只是感觉笨重,和那种失败的IDE点,是红隼配置为使用HTTPS。这不是理想的,因为我不得不从IIS导出证书的副本本地主机,和IIS快递仍然尝试加载网站不同的端口上。

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();
    }
}

可悲的是,从VS17运行时,这是行不通的。第一次围绕我得到了502.2(我认为)的错误,现在我得到的是一个无法在Chrome连接错误。我可以从PowerShell中运行dotnet run并能正常工作。

作为一种变通方法,但它的伎俩。但它似乎并不整齐。

ssl https kestrel-http-server visual-studio-2017
9个回答
50
投票

端口在IIS快速锁定,使其不必以管理员身份运行...

有效的端口是44300 - 44399

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

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


46
投票

这是一个Asp.Net MVC .Net框架项目

  1. 通过突出显示选择您的项目。
  2. 然后点击F4打开其属性面板。
  3. 查找列表中启用SSL项目,并将其值设置为True,以及SSL URL值复制到剪贴板上。
  4. 虽然你的项目被选中,按下Alt + Enter键打开属性对话框 - 复制的SSL URL粘贴到Web菜单输入框下的项目的URL。

11
投票

对于Visual Studio 2017年:

  1. 在解决方案资源管理器中,右键单击项目>属性
  2. 选择调试选项卡
  3. 检查启用SSL enter image description here

5
投票

在您的网站名称并选择“属性窗口” Solution Explorer中右键点击,或者干脆打F4。在开发Web服务器区间变化启用SSL从假到真。


4
投票

对于那些在Visual Studio 2017年RC运行asp.net核心1.x中,你应该能够改变“sslPort”:在launchSettings.json文件到任何端口号,你想使用SSL 0线。这有效地改变了绑定的。\ VS \ CONFIG \对ApplicationHost.config在前面的答案中提到的文件。


4
投票

这是一个Asp.Net核2.0:

  1. 在VS2017打开你的解决方案管理器。
  2. 双击Properties(是的,它是一个对象本身也是如此,不只是一个文件夹)
  3. 左侧开Debug
  4. 向下滚动并选择Enable SSL

如果已经启用,开拓launchSettings.json(展开Properties),并设置"sslPort"0,然后再次做的步骤。

VS2017现在应该问你,如果你想添加SSL证书(的东西,如果你对自己的改变launchSettings.json它不会做),它会设置一个端口为您服务。


2
投票

编辑对我实际工作的.\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>

它默认情况下使用非HTTPS端口但是加载应用了在浏览器中。如果您手动将浏览器指向到43107端口它应该工作。

编辑

这为我工作了几次,但停止工作。随后的测试发现,每当我会点击该按钮,在VS 2017年开始调试RC它将删除我手动添加绑定。

我固定,通过使该文件为只读现在它再次开始使用HTTPS的支持。


1
投票

不幸的是我有同样的问题,不能看到“启用SSL”复选框,在项目的属性...终于找到它的调试选项卡! - >设置在“IIS快车”的推出,那么你就可以选择它;-)


0
投票

您可能会丢失重要的一点是,你必须运行Visual Studio为adminsitrator(右vlick VS图标,选择“以管理员身份运行”。我一直在strugling这个SSL问题,之后通过运行VS作为管理员联系我做了它的工作。

© www.soinside.com 2019 - 2024. All rights reserved.