Visual Studio 2017启用SSL
如何在Visual Studio 2017中为项目启用SSL 在VS15中,我可以选择项目->属性->调试->启用SSL。此选项在VS2017中不可用。它搬到哪里去了 编辑: 我甚至尝试过编辑Visual Studio 2017启用SSL,ssl,https,kestrel-http-server,visual-studio-2017,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" />
\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导出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();
}
}
公共类程序
{
公共静态void Main(字符串[]args)
{
var host=new WebHostBuilder()
.UseKestrel(选项=>
options.UseHttps(新的X509Certificate2(“path/to/cert.pfx”,“password”))
.UseContentRoot(目录.GetCurrentDirectory())
.useURL(“http://localhost:5100", "https://localhost:4300")
.Useii整合()
.UseStartup()
.Build();
host.Run();
}
}
遗憾的是,当从VS17运行时,这不起作用。我第一次遇到502.2(我想)错误,现在我得到的只是Chrome中的无法连接错误。我可以从PowerShell运行dotnet运行
,它工作正常
作为一种变通方法,它确实起到了作用。但是它看起来并不整洁。编辑
\vs\config\applicationhost.config
实际上对我很有用
****
但是,默认情况下,它会使用非https端口在浏览器中加载应用程序。如果手动将浏览器指向43107端口,它应该可以工作
编辑
这对我有用几次,但都停止了。随后的测试显示,每当我在VS2017 RC中单击按钮开始调试时,它都会删除我手动添加的绑定
我修复了这个问题,通过将文件设置为只读,现在又开始使用HTTPS支持。对于在Visual Studio 2017 RC中运行asp.net core 1.x的用户,您应该能够将launchSettings.json文件中的“sslPort”:0行更改为您希望用于SSL的任何端口号。这将有效地更改前面回答中提到的.\vs\config\applicationhost.config文件中的绑定。对于Visual Studio 2019和2017:
在解决方案资源管理器中,右键单击您的网站名称并选择“属性窗口”,或者只需点击F4。在DeveloperWeb服务器部分下,将启用的SSL从False更改为True 您可能缺少的一点是,您必须以管理员身份运行Visual Studio(右键单击VS图标并选择“以管理员身份运行”)。
我一直在为这个SSL问题绞尽脑汁,在以管理员身份运行VS之后,我使它正常工作。IIS Express中的端口被锁定,因此它不必以管理员身份运行 有效端口为44300-44399 查看Dev社区文章 您可以编辑launchSettings.json,但ssl端口必须在此范围内。这适用于Asp.Net MVC.Net Framework项目
Debug
启用SSL
launchSettings.json
(展开Properties
)并将“sslPort”
设置为0
,然后再次执行这些步骤
VS2017现在应该询问您是否要添加SSL证书(如果您自己更改了launchSettings.json
,它不会这样做),它会为您设置一个端口。
不幸的是,我遇到了同样的问题,无法在项目属性的调试选项卡中看到“启用SSL”复选框。。。
终于找到了!-->在“IIS Express”上设置启动,然后您就可以选择它;-)如果您在项目的“属性”窗口下看到启用SSL的选项,但该选项变灰了
还是有点“黑客”的解决方法,但我会尝试将文件设置为只读,以防止覆盖配置选项。至少我应该能够再次运行VS中的所有内容。如果您想避免“黑客”解决方案,请执行以下操作:1.在解决方案资源管理器上打开应用程序的属性。2.选择调试。3.启用SSL。@Allan你应该加上它作为答案,这样我