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
您可以编辑launchSettings.json,但ssl端口必须在此范围内.
小智 48
这是针对Asp.Net MVC .Net Framework项目的
Ric*_*SFT 11
对于Visual Studio 2017:
小智 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。
编辑.\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。
| 归档时间: |
|
| 查看次数: |
40296 次 |
| 最近记录: |