Visual Studio 2017启用SSL [英] Visual Studio 2017 Enable SSL

查看:145
本文介绍了Visual Studio 2017启用SSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do you enable SSL for a project in Visual Studio 2017?

在VS15中,我可以选择项目"->属性"->调试"->启用SSL".该选项在VS2017中不可用.它搬到哪里了?

In VS15, I could select Project -> Properties -> Debug -> Enable SSL. This option is not available in VS2017. Where has it moved to?

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

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

我尝试过的另一种选择是将Kestrel配置为使用HTTPS,这感觉很笨拙,并且有点违反IDE的观点.这是不理想的,因为我必须从IIS导出本地主机的证书副本,并且IIS Express仍尝试将站点加载到其他端口上.

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

可悲的是,从VS17运行时,此方法不起作用.我第一次遇到502.2(我认为)错误,现在我得到的只是Chrome中无法连接的错误.我可以从PowerShell中运行dotnet 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.

推荐答案

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

Ports are locked down in IIS Express so that it doesn't have to be run as Administrator...

有效端口为44300-44399

Valid Ports are 44300 - 44399

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

Check out the Dev Community article https://developercommunity.visualstudio.com/content/problem/39430/changing-port-number-in-a-web-project-does-not-imm.html

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

You can edit launchSettings.json, but the ssl ports must fall in this range.

这篇关于Visual Studio 2017启用SSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆