【问题标题】:Enable SSL in Visual Studio - not prompted to install certificate在 Visual Studio 中启用 SSL - 未提示安装证书
【发布时间】:2016-08-28 09:20:17
【问题描述】:

我正在尝试按照这篇文章中的说明进行操作:http://www.codeproject.com/Tips/766918/Visual-Studio-Use-HTTPS-SSL-On-Web-Application-Pro。我没有收到消息“您想信任 IIS SSL 证书吗?”的提示。

证书存储中没有出现证书,如下所示:

请问我做错了什么?请在此处查看我在 Visual Studio 中启动应用程序时从 IE 和 Firefox 收到的警告:Enable SSL in Visual Studio

【问题讨论】:

  • 您使用 Visual Studio 的哪个版本?您的计算机是否有公共 DNS 名称(例如通过使用动态 DNS),或者您希望在您的计算机上仅在本地使用 SSL,并且您的网站不应通过 SSL 从外部访问?问题是:客户端和服务器之间将建立 SSL,双方都必须信任证书。
  • 如果您需要自签名证书,那么使用makecert.exe是最简单明了的生成和安装证书的方法。如果您的计算机具有公共 DNS 名称,那么创建公共 SSL 证书将是最佳选择。您可以从许多提供者那里免费获得此类证书。它将简化任何未来的使用场景。
  • @Oleg,我取得了一些进展。看我的回答。唯一的困惑是我不必根据您在此处的链接在 ApplicationHost.config 文件中创建绑定:hanselman.com/blog/…。你知道为什么吗?
  • 请回答我多次问过您的问题:“您使用的是哪个版本的 Visual Studio?” 关于绑定:您可以打开 %USERPROFILE%\Documents\IISExpress\config\applicationhost.config 并搜索 @ 987654328@ 或 <binding protocol="https" 在您尝试与 SSL 一起使用的 <site> 内。我想你确实做了绑定。
  • @oleg,对不起,它是 Visual Studio 2015 社区版。这是一个本地主机。

标签: c# .net visual-studio ssl


【解决方案1】:

将 IIS Express 配置为使用 SSL 包括许多步骤,在第一次使用时有些棘手。必须做的最重要的部分如下:

  • 创建/获取/生成 SSL 证书。例如,可以使用MakeCert.exe 来生成自签名证书。查看%ProgramFiles(x86)%\Windows Kits\10\bin\x64%ProgramFiles(x86)%\Windows Kits\8.1\bin\x64 以获取MakeCert.exe 实用程序。证书必须另外导入“受信任的根证书颁发机构”或“第三方根证书颁发机构”,以使其在本地计算机(或本地用户)上受信任。
  • IIS Express 使用操作系统的底层 HTTP.SYS 来处理所有 HTTP/HTTPS 请求。因此,必须对其进行配置,例如,使用 netsh http add sslcert ...netsh http add urlacl ... 或使用带有 setupFriendlyHostnameUrl 参数的 "%ProgramFiles%\IIS Express\IisExpressAdminCmd.exe" 实用程序。
  • 将 Visual Studio 项目配置为使用 HTTPS 进行调试并为 IIS Express 创建与 HTTPS 的绑定。一个人可以在没有 Visual Studio 的情况下运行 IIS Express。然后包括网站的新<binding> 问题应包含在%USERPROFILE%\Documents\IISExpress\config\applicationhost.co‌​‌​‌​nfig 中。如果仅在 Visual Studio 内部使用 IIS Express,则 Visual Studio 将在 $(solutionDir)\.vs\config\applicationhost.config 文件中插入相应的绑定。

我建议您阅读并关注 Hanselman 在 2011 年发布的the old article。该信息今天仍然有罪。

【讨论】:

    【解决方案2】:

    我按照以下步骤取得了一些进展:

        1) Click on the project name then F4 or View -> Properties Window
        2) Set SSL Enabled to: True
        3) Make a note of the SSL URL that is generated.  In my case it is: https://localhost:44334/
        4) Right click on the project name and select: Properties
        5) Set Project URL to the URL noted in step 3 i.e. https://localhost:44334/
        6) Open up a command prompt and run: "C:\Program Files (x86)\Windows Kits\8.1\bin\x64\makecert.exe"  -r -pe -n "CN=localhost" -b 01/01/2000 -e 01/01/2036 -eku 1.3.6.1.5.5.7.3.1 -ss my -sr localMachine -sky exchange -sp "Microsoft RSA SChannel Cryptographic Provider" -sy 12.  
        7) Go to mmc.exe and get the thumbprint of the certificate
        8) Run the following from a command line: netsh http add sslcert ipport=0.0.0.0:44334 appid={214124cd-d05b-4309-9af9-9caa44b2b74a} certhash=2f11d025f2bc8802b45ceb7e03632eec333bc1ff.  2f11d025f2bc8802b45ceb7e03632eec333bc1ff is the thumbprint from step 8 and 44334 is the port from step 3.
        9) Run: netsh http add urlacl url=https://localhost:44334/ user=Everyone
        10) Launch the web app and I see this (
    which looks a lot better):
    

    11) 前往 MMC 找到“个人”证书,然后将其移至:Trusted Root Certification Authorities。

    然后就可以了。

    上述所有步骤都可以在这篇文章中找到:http://www.hanselman.com/blog/WorkingWithSSLAtDevelopmentTimeIsEasierWithIISExpress.aspx。我已经总结了我所遵循的步骤,以防我(或其他任何人)将来想要参考它——这篇文章很长。请注意,在我的例子中:applicationhost.config 是由 Visual Studio 自动写入的,而在链接中作者建议您手动写入以下文件:C:\Users\Ian\Documents\IISExpress\config\applicationhost.config。我的 application.config 文件位于 .vs\config 文件夹中。

    【讨论】:

    • 您应该尝试 Jexus Manager Jexusmanager.com,它使用 IIS 管理器样式向导简化了步骤。
    【解决方案3】:

    只需修复您的 Visual Studio 以重新生成 IIS Express 开发证书。

    【讨论】:

    • 这适用于哪些版本的 Visual Studio?
    • 我将此应用到 16.10.1
    猜你喜欢
    • 2015-08-20
    • 1970-01-01
    • 2021-08-20
    • 2016-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-05
    • 1970-01-01
    相关资源
    最近更新 更多