ssl - Visual Studio 2017 启用 SSL

标签 ssl https kestrel-http-server visual-studio-2017

如何在 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 />

编辑:

我尝试过的另一个选项是将 Kestrel 配置为使用 HTTPS,这感觉很笨拙,并且有点违背 IDE 的意义。这并不理想,因为我必须从 IIS 导出本地主机的证书副本,而 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();
    }
}

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

作为解决方法,它可以解决问题。但这似乎并不整洁。

最佳答案

端口在 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 端口必须在此范围内。

关于ssl - Visual Studio 2017 启用 SSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41075478/

相关文章:

ssl - 使用 openssl s_client 连接到 EPP 服务器时出错

delphi - Wininet SSL 客户端验证异常

html - 在安全页面上嵌入不安全的 Flash 对象

angularjs - 使用自签名证书对服务器进行 ajax 调用。

docker - ASP.net Core Web App 在 Docker 容器中运行时未接收请求

php - Paypal 访问 - SSL 证书 : unable to get local issuer certificate

c# - .NET C# "The remote certificate is invalid according to the validation procedure"

c# - 通过 HTTPS 的 HttpWebRequest 的随机问题

ssl - 如何在 ASP.NET Core 2.x 中将 HTTPS/SSL 与 Kestrel 一起使用?

asp.net-core - 如何停止自托管 Kestrel 应用程序?